Last active
June 9, 2016 14:00
-
-
Save yuki-teraoka/0d64de68eea8c7d9f1df1df8a38f843e 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": "create LookupStackOutputs LambdaHandler ", | |
"Parameters": {}, | |
"Resources" : { | |
"LookupStackOutputs": { | |
"Type": "AWS::Lambda::Function", | |
"Properties": { | |
"Handler": "index.handler", | |
"FunctionName": "LookupStackOutputs", | |
"Role": { "Fn::GetAtt" : ["LambdaExecutionRole", "Arn"] }, | |
"Code": { | |
"ZipFile": { "Fn::Join": ["\n", [ | |
"var response = require('cfn-response');", | |
"exports.handler = function(event, context) {", | |
" console.log('REQUEST RECEIVED:\\n', JSON.stringify(event));", | |
" if (event.RequestType == 'Delete') {", | |
" response.send(event, context, response.SUCCESS);", | |
" return;", | |
" }", | |
" var stackName = event.ResourceProperties.StackName;", | |
" var responseData = {};", | |
" if (stackName) {", | |
" var aws = require('aws-sdk');", | |
" var cfn = new aws.CloudFormation();", | |
" cfn.describeStacks({StackName: stackName}, function(err, data) {", | |
" if (err) {", | |
" responseData = {Error: 'DescribeStacks call failed'};", | |
" console.log(responseData.Error + ':\\n', err);", | |
" response.send(event, context, response.FAILED, responseData);", | |
" }", | |
" else {", | |
" data.Stacks[0].Outputs.forEach(function(output) {", | |
" responseData[output.OutputKey] = output.OutputValue;", | |
" });", | |
" response.send(event, context, response.SUCCESS, responseData);", | |
" }", | |
" });", | |
" } else {", | |
" responseData = {Error: 'Stack name not specified'};", | |
" console.log(responseData.Error);", | |
" response.send(event, context, response.FAILED, responseData);", | |
" }", | |
"};" | |
]]} | |
}, | |
"Runtime": "nodejs", | |
"Timeout": "30" | |
} | |
}, | |
"LambdaExecutionRole": { | |
"Type": "AWS::IAM::Role", | |
"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": ["logs:CreateLogGroup","logs:CreateLogStream","logs:PutLogEvents"], | |
"Resource": "arn:aws:logs:*:*:*" | |
}, | |
{ | |
"Effect": "Allow", | |
"Action": ["cloudformation:DescribeStacks"], | |
"Resource": "*" | |
}] | |
} | |
}] | |
} | |
} | |
}, | |
"Outputs" : { | |
"ServiceToken" : { | |
"Value" : { "Fn::GetAtt" : [ "LookupStackOutputs", "Arn" ]} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment