Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
CloudFormation Custom Resource Experiments
---
AWSTemplateFormatVersion: 2010-09-09
Parameters:
Param:
Type: String
Default: v1
Resources:
MyCustomResource:
Type: Custom::MyResouce
Properties:
ServiceToken: !Sub |-
${MyLambdaFunction.Arn}
Param: !Sub |-
${Param}
MyLambdaFunction:
Type: AWS::Lambda::Function
Properties:
Code:
ZipFile: >
var response = require('cfn-response');
exports.handler = function(event, context) {
response.send(event, context, response.SUCCESS, {});
};
Handler: index.handler
Role: !Sub |-
${MyRole.Arn}
Runtime: nodejs4.3
MyRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: CloudWatchLogs
PolicyDocument:
Statement:
- Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Effect: Allow
Resource: arn:aws:logs:*:*:*
---
AWSTemplateFormatVersion: 2010-09-09
Parameters:
Param:
Type: String
Default: v1
Resources:
MyCustomResource:
Type: Custom::MyResouce
Properties:
ServiceToken: !Sub |-
${MyLambdaFunction.Arn}
Param: !Sub |-
${Param}
MyLambdaFunction:
Type: AWS::Lambda::Function
Properties:
Code:
ZipFile: >
var response = require('cfn-response');
exports.handler = function(event, context) {
response.send(event, context, response.SUCCESS, {}, 'PhysicalResourceID');
};
Handler: index.handler
Role: !Sub |-
${MyRole.Arn}
Runtime: nodejs4.3
MyRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: CloudWatchLogs
PolicyDocument:
Statement:
- Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Effect: Allow
Resource: arn:aws:logs:*:*:*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment