Last active
May 19, 2017 23:32
-
-
Save estahn/f9649027fb6c4dec7dee7afd9cdd29a7 to your computer and use it in GitHub Desktop.
lambda-formation Custom::Route53::HostedZone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var handler = require('lambda-formation').resource.create; | |
var util = require('lambda-formation').util; | |
var aws = require("aws-sdk"); | |
var uuidV4 = require('uuid/v4'); | |
/** | |
* Creates a Hosted Zone and supports delegation sets | |
* | |
* Type: "AWS::Route53::HostedZone" | |
* Properties: | |
* DelegationSetId: String | |
* HostedZoneConfig: | |
* HostedZoneConfig | |
* HostedZoneTags: | |
* - HostedZoneTags | |
* Name: String | |
* VPCs: | |
* - HostedZoneVPCs | |
* NSRecords: | |
* - NSRecords | |
* SOARecord: String | |
* | |
* @param err | |
* @param event | |
* @param context | |
* @see http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Route53.html#createHostedZone-property | |
*/ | |
var create = function (err, event, context) { | |
if (err) { | |
return util.done(err); | |
} | |
var route53 = new aws.Route53(); | |
var params = event.ResourceProperties; | |
var tags = event.ResourceProperties.HostedZoneTags || {}; | |
// We pass resource properties directly to createHostedZone to reduce code but still need to do | |
// some cleanup from Cloudformation request. | |
delete params.ServiceToken; | |
delete params.HostedZoneTags; | |
// delete params.NSRecords; | |
// delete params.SOARecord; | |
params.CallerReference = uuidV4(); | |
if (event.ResourceProperties.DelegationSetId) { | |
params.DelegationSetId = event.ResourceProperties.DelegationSetId; | |
} | |
console.log(params); | |
route53.createHostedZone(params, function(err, data) { | |
console.log(JSON.stringify(err), JSON.stringify(data)); | |
if (err) { | |
return util.done(err, event, context, {}, 'ID'); | |
} | |
return util.done(null, event, context, data, data.HostedZone.Id); | |
}); | |
}; | |
/* Do not change this function */ | |
module.exports.handler = function (event, context) { | |
handler.apply(this, [event, context, create]); | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var handler = require('lambda-formation').resource.delete; | |
var util = require('lambda-formation').util; | |
var aws = require("aws-sdk"); | |
var destroy = function (err, event, context) { | |
if (err) { | |
return util.done(err); | |
} | |
var route53 = new aws.Route53(); | |
var params = {Id: event.PhysicalResourceId}; | |
console.log(params); | |
route53.deleteHostedZone(params, function (err, data) { | |
console.log(JSON.stringify(err), JSON.stringify(data)); | |
if (err) { | |
return util.done(err, event, context, data, 'ID'); | |
} | |
return util.done(null, event, context, data, data.Id); | |
}); | |
}; | |
/* Do not change this function */ | |
module.exports.handler = function (event, context) { | |
handler.apply(this, [event, context, destroy]); | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var resourceHandler = require('lambda-formation').resource.handler; | |
module.exports.handler = function () { | |
resourceHandler.apply(this, arguments); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var handler = require('lambda-formation').resource.update; | |
var util = require('lambda-formation').util; | |
var aws = require("aws-sdk"); | |
var create = require('./create'); | |
var update = function (err, event, context) { | |
if (err) { | |
return util.done(err); | |
} | |
var route53 = new aws.Route53(); | |
var params = {Id: event.PhysicalResourceId}; | |
route53.deleteHostedZone(params, function (err, data) { | |
if (err) { | |
return util.done(err, event, context, data, 'ID'); | |
} | |
return create(err, event, context); | |
}); | |
}; | |
/* Do not change this function */ | |
module.exports.handler = function (event, context) { | |
handler.apply(this, [event, context, update]); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment