Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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