Skip to content

Instantly share code, notes, and snippets.

View jsywulak's full-sized avatar

Jonathan Sywulak jsywulak

View GitHub Profile
custom_function_arn=$(aws cloudformation describe-stacks --stack-name $create_stack --query Stacks[*].Outputs[?OutputKey==\'CustomFunctionArn\'].OutputValue --output text) 
aws cloudformation create-stack \ 
... 
--parameters \
ParameterKey="CustomFunctionArn",ParameterValue="$custom_function_arn" 
Outputs:
CustomFunctionArn:
Description: The arn of the custom resource function.
Value: !GetAtt 'CustomFunction.Arn'
Resources:
  CustomFunction:
    Type: AWS::Lambda::Function
    Properties
...
CustomResource:
    Type: Custom::CustomResource
    Properties:
      ServiceToken: !GetAtt 'CustomFunction.Arn'
LambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
Policies:
- PolicyName: root
PolicyDocument:
Version: '2012-10-17'
Statement:
... 
Resources:
  CustomFunction:
    Type: AWS::Lambda::Function
    Properties:
      Code:
        S3Bucket: !Ref 'S3Bucket'
        S3Key: !Ref 'S3Key'
...
Parameters: 
    S3Bucket: 
    Description: The name of the bucket that contains your packaged source 
    Type: String 
  S3Key: 
    Description: The name of the ZIP package 
    Type: String 
    Default: custom-resource.zip 
zip /tmp/custom-resource.zip customresource.js 
aws s3 cp /tmp/custom-resource.zip s3://your-custom-resource-code-bucket/custom-resource.zip