Created
August 9, 2016 13:52
-
-
Save ChrisBlom/2a13b0c1bc7585cd4169da21ed9ce35e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
{"AWSTemplateFormatVersion":"2010-09-09", | |
"Description":"Creates a classic-link enabled VPC, the custom resource hangs", | |
"Parameters":{}, | |
"Resources": | |
{"VPC": | |
{"Type":"AWS::EC2::VPC", | |
"Properties": | |
{"EnableDnsSupport":true, | |
"EnableDnsHostnames":true, | |
"CidrBlock":"10.0.0.0/16", | |
"Tags": | |
[{"Key":"Application", "Value":{"Ref":"AWS::StackName"}}, | |
{"Key":"Network", "Value":"Public"}, | |
{"Key":"Name", | |
"Value": | |
{"Fn::Join": | |
["", [{"Ref":"AWS::StackName"}, "-classiclink-enabled"]]}}]}}, | |
"LambdaExecutionRole": | |
{"Type":"AWS::IAM::Role", | |
"DependsOn":["VPC"], | |
"Properties": | |
{"AssumeRolePolicyDocument": | |
{"Version":"2012-10-17", | |
"Statement": | |
[{"Effect":"Allow", | |
"Principal":{"Service":["lambda.amazonaws.com"]}, | |
"Action":["sts:AssumeRole"]}]}, | |
"Path":"/", | |
"Policies": | |
[{"PolicyName":"root", | |
"PolicyDocument": | |
{"Version":"2012-10-17", | |
"Statement": | |
[{"Effect":"Allow", | |
"Action":["ec2:EnableVpcClassicLink"], | |
"Resource":"*"}, | |
{"Effect":"Allow", | |
"Action": | |
["logs:CreateLogGroup", "logs:CreateLogStream", | |
"logs:PutLogEvents", "logs:DescribeLogStreams"], | |
"Resource":"*"}]}}]}}, | |
"EnableClassicLinkFunction": | |
{"Type":"AWS::Lambda::Function", | |
"Properties": | |
{"Description": | |
"enables classiclink on the vpc (CFN does not support this directly)", | |
"Code": | |
{"ZipFile": | |
{"Fn::Join": | |
["\n", | |
["exports.handler = function(event,context) {", | |
" console.log('REQUEST RECEIVED:\\n', JSON.stringify(event));", | |
"", " var response = require('cfn-response');", "", | |
" // For Delete requests, immediately send a SUCCESS response.", | |
" if (event.RequestType == \"Delete\") {", | |
" sendResponse(event, context, \"SUCCESS\");", | |
" return;", " }", "", | |
" var AWS = require('aws-sdk');", | |
" var ec2 = new AWS.EC2();", "", | |
" var responseData = {};", "", | |
" if (event.ResourceProperties.VPCId) {", | |
" console.log('Enabling VPC classiclink');", | |
" ec2.enableVpcClassicLink({ VpcId: event.ResourceProperties.VPCId,", | |
" DryRun: false}", | |
" , function(err, data) {", | |
" if (err) {", | |
" console.log(err, err.stack);", | |
" responseData = {Error: 'enableVpcClassicLink failed'};", | |
" response.send(event, context, response.FAILED, responseData);", | |
" }", | |
" else {", | |
" console.log(data); // successful response", | |
" responseData = {Success: 'enableVpcClassicLink succeeded'};", | |
" response.send(event, context, response.SUCCESS, responseData);", | |
" }});", " } else {", | |
" responseData = {Error: 'enableVpcClassicLink failed: event.ResourceProperties.VPCId is missing'};", | |
" response.send(event, context, response.FAILED, responseData);", | |
" };", "};"]]}}, | |
"Handler":"index.handler", | |
"MemorySize":128, | |
"Role":{"Fn::GetAtt":["LambdaExecutionRole", "Arn"]}, | |
"Runtime":"nodejs4.3", | |
"Timeout":30}}, | |
"EnableClassicLink": | |
{"Type":"Custom::EnableClassicLink", | |
"DependsOn":["EnableClassicLinkFunction", "VPC"], | |
"Properties": | |
{"ServiceToken": | |
{"Fn::GetAtt":["EnableClassicLinkFunction", "Arn"]}, | |
"VPCId":{"Ref":"VPC"}}}}, | |
"Outputs": | |
{"VPCId": | |
{"Description":"VPCId of the newly created VPC", | |
"Value":{"Ref":"VPC"}}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment