Skip to content

Instantly share code, notes, and snippets.

@atward
Created November 21, 2016 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atward/0903acd45284255d2094f7a8165255ad to your computer and use it in GitHub Desktop.
Save atward/0903acd45284255d2094f7a8165255ad to your computer and use it in GitHub Desktop.
AWS Custom resource example. Multiplies number by 42
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