Skip to content

Instantly share code, notes, and snippets.

@ks888
Created May 13, 2017 04:42
Show Gist options
  • Save ks888/fb07b474fad5d034a46e0a3b8d10e44f to your computer and use it in GitHub Desktop.
Save ks888/fb07b474fad5d034a46e0a3b8d10e44f to your computer and use it in GitHub Desktop.
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