Skip to content
This repository was archived by the owner on Oct 9, 2021. It is now read-only.

Commit fe164ab

Browse files
committed
add CFN custom resource files
1 parent f00ef03 commit fe164ab

File tree

318 files changed

+128647
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

318 files changed

+128647
-0
lines changed
Binary file not shown.

CloudFormation/CustomResources/APIGatewayCreateScript/src/ApiGatewayCreate.js

Lines changed: 614 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
var AWS = require('aws-sdk');
2+
3+
var apigateway;
4+
var apigatewayuuid;
5+
6+
module.exports = {
7+
deleteGateway:function(event, context, callback)
8+
{
9+
console.log('deleting gateway, parameters passed in: ');
10+
console.log(event);
11+
12+
region = event.ResourceProperties.region;
13+
apigatewayuuid = event.StackId;
14+
15+
AWS.config.update({region: region});
16+
apigateway = new AWS.APIGateway();
17+
18+
deleteGatewayImplementation(callback);
19+
}
20+
}
21+
22+
function deleteGatewayImplementation(callback)
23+
{
24+
var params = {};
25+
apigateway.getRestApis(params, function(err, data) {
26+
if (!err)
27+
{
28+
console.log('finding api gateway in list');
29+
for (var i = 0; i < data.items.length; i++)
30+
{
31+
if(data.items[i].description == apigatewayuuid)
32+
{
33+
console.log('found gateway, deleting...');
34+
var params = {
35+
restApiId: data.items[i].id
36+
};
37+
apigateway.deleteRestApi(params, function(err, data) {
38+
if (!err)
39+
{
40+
console.log('successfully deleted api gateway');
41+
callback(null);
42+
43+
}
44+
else
45+
{
46+
callback(err);
47+
}
48+
});
49+
}
50+
}
51+
}
52+
else
53+
{
54+
console.log(err, err.stack);
55+
callback(err);
56+
}
57+
});
58+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* New node file
3+
*/
4+
5+
var AWS = require('aws-sdk');
6+
var apigatewaycreate = require('./ApiGatewayCreate');
7+
var apigatewaydelete = require('./ApiGatewayDelete');
8+
var cloudformationsender = require('./cloudformationsender');
9+
var zombieconfigupdater = require('./ZombieWebsiteConfigUpdate');
10+
11+
var theRegion;
12+
var theS3Bucket;
13+
var theS3Key
14+
var theEvent;
15+
var theContext;
16+
17+
exports.handleGatewayEvent = function(event, context)
18+
{
19+
20+
theEvent = event;
21+
theContext = context;
22+
23+
if(event.RequestType == 'Create')
24+
{
25+
theRegion = event.ResourceProperties.region;
26+
theS3Bucket = event.ResourceProperties.s3bucket;
27+
theS3Key = event.ResourceProperties.s3key;
28+
29+
AWS.config.update({region: theRegion});
30+
31+
apigatewaycreate.createGateway(event, context, createApiGatewayCallback);
32+
}
33+
else if(event.RequestType == 'Delete')
34+
{
35+
apigatewaydelete.deleteGateway(event, context, finishedUpdatingCallback);
36+
}
37+
else
38+
{
39+
console.log(event);
40+
console.log('non-create requst type, sending suceed');
41+
cloudformationsender.sendResponse(event, context, "SUCCESS", {});
42+
}
43+
}
44+
45+
function createApiGatewayCallback(err, restAPIId)
46+
{
47+
if(err)
48+
{
49+
console.log(err, err.stack);
50+
cloudformationsender.sendResponse(theEvent,
51+
theContext, "FAILED", {});
52+
}
53+
else
54+
{
55+
var url = "https://" + restAPIId + ".execute-api." + theRegion +
56+
".amazonaws.com/ZombieWorkshopStage/zombie/message";
57+
58+
console.log("calling s3 helper to create constants with url: " + url);
59+
60+
zombieconfigupdater.updateConfig(theRegion,
61+
theS3Key,
62+
theS3Bucket,
63+
url,
64+
finishedUpdatingCallback);
65+
}
66+
}
67+
68+
/**
69+
* callback that looks if it's an error and updates cloudformation appropriately...
70+
* @param err
71+
*/
72+
function finishedUpdatingCallback(err)
73+
{
74+
75+
if(err)
76+
{
77+
cloudformationsender.sendResponse(theEvent,
78+
theContext, "FAILED", {});
79+
}
80+
else
81+
{
82+
cloudformationsender.sendResponse(theEvent,
83+
theContext, "SUCCESS", {});
84+
}
85+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* This module writes the file out in the format needed for the website.
3+
* the S3 bucket/key and the url is passed in, and it writes the javascript file out.
4+
*/
5+
var AWS = require('aws-sdk');
6+
module.exports = {
7+
updateConfig:function(region, s3key, s3bucketName, url, callback)
8+
{
9+
console.log('updating Zombie S3 web page located at: ' + s3key + ' and ' + s3bucketName);
10+
11+
AWS.config.update({region: region});
12+
13+
var s3bucket = new AWS.S3({params: {Bucket: s3bucketName}});
14+
s3bucket.createBucket(function() {
15+
var params = {Key: s3key, Body: 'var MESSAGES_ENDPOINT = "' + url + '";'};
16+
s3bucket.upload(params, function(err, data) {
17+
if (err) {
18+
callback(err);
19+
} else {
20+
callback(null);
21+
}
22+
});
23+
});
24+
}
25+
}
26+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* New node file
3+
*/
4+
5+
module.exports = {
6+
sendResponse: function(event, context, responseStatus, responseData) {
7+
8+
var responseBody = JSON.stringify({
9+
Status: responseStatus,
10+
Reason: "See the details in CloudWatch Log Stream: " + context.logStreamName,
11+
PhysicalResourceId: context.logStreamName,
12+
StackId: event.StackId,
13+
RequestId: event.RequestId,
14+
LogicalResourceId: event.LogicalResourceId,
15+
Data: responseData
16+
});
17+
18+
console.log("RESPONSE BODY:\n", responseBody);
19+
20+
var https = require("https");
21+
var url = require("url");
22+
23+
var parsedUrl = url.parse(event.ResponseURL);
24+
var options = {
25+
hostname: parsedUrl.hostname,
26+
port: 443,
27+
path: parsedUrl.path,
28+
method: "PUT",
29+
headers: {
30+
"content-type": "",
31+
"content-length": responseBody.length
32+
}
33+
};
34+
35+
console.log("SENDING RESPONSE...\n");
36+
37+
var request = https.request(options, function(response) {
38+
console.log("STATUS: " + response.statusCode);
39+
console.log("HEADERS: " + JSON.stringify(response.headers));
40+
// Tell AWS Lambda that the function execution is done
41+
context.done();
42+
});
43+
44+
request.on("error", function(error) {
45+
console.log("sendResponse Error:" + error);
46+
// Tell AWS Lambda that the function execution is done
47+
context.done();
48+
});
49+
50+
// write data to request body
51+
request.write(responseBody);
52+
request.end();
53+
}
54+
}

CloudFormation/CustomResources/APIGatewayCreateScript/src/node_modules/async/CHANGELOG.md

Lines changed: 113 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CloudFormation/CustomResources/APIGatewayCreateScript/src/node_modules/async/LICENSE

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)