Created
November 21, 2016 04:04
-
-
Save atward/0903acd45284255d2094f7a8165255ad to your computer and use it in GitHub Desktop.
AWS Custom resource example. Multiplies number by 42
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: 'Custom resource test' | |
Parameters: | |
Value: | |
Type: Number | |
Description: input a number | |
Default: 1 | |
Resources: | |
FooRole: | |
Type: AWS::IAM::Role | |
Properties: | |
AssumeRolePolicyDocument: | |
Version: 2012-10-17 | |
Statement: | |
- Action: ['sts:AssumeRole'] | |
Effect: Allow | |
Principal: | |
Service: [lambda.amazonaws.com] | |
FooFunction: | |
Type: AWS::Lambda::Function | |
Properties: | |
Code: | |
ZipFile: | | |
import json | |
import cfnresponse | |
def handler(event, context): | |
responseValue = int(event['ResourceProperties']['Input']) * 42 | |
responseData = {} | |
responseData['Data'] = responseValue | |
cfnresponse.send(event, context, cfnresponse.SUCCESS, responseData, "CustomResourcePhysicalID") | |
Handler: index.handler | |
Role: !GetAtt FooRole.Arn | |
Runtime: 'python2.7' | |
Foo: | |
Type: Custom::Foo | |
Version: 1.0 | |
Properties: | |
ServiceToken: !GetAtt FooFunction.Arn | |
Input: !Ref Value | |
Outputs: | |
Results: | |
Value: !GetAtt Foo.Data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment