Skip to content

Instantly share code, notes, and snippets.

@corpulentcoffee
Created September 23, 2018 22:20
Show Gist options
  • Save corpulentcoffee/46cdd4530be94723f6e870b8d750f61f to your computer and use it in GitHub Desktop.
Save corpulentcoffee/46cdd4530be94723f6e870b8d750f61f to your computer and use it in GitHub Desktop.
Example use of the Serverless transform's AutoPublishAlias feature in a CloudFormation stack of a CloudFront distribution with a custom Lambda handler
Transform: AWS::Serverless-2016-10-31
Resources:
CDN:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
# . . .
DefaultCacheBehavior:
# . . .
LambdaFunctionAssociations:
- # . . .
LambdaFunctionARN: !Ref Handler.Version # via AutoPublishAlias
Handler:
Type: AWS::Serverless::Function # avails AutoPublishAlias (and CodeUri)
Properties:
CodeUri: handler-function
Handler: index.handler
Role: !GetAtt [HandlerRole, Arn] # no edgelambda in SAM-created assume
# role policy, so must do it manually
Runtime: nodejs8.10
Timeout: 1
AutoPublishAlias: Live # creates new published version on every change
HandlerRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: [lambda.amazonaws.com, edgelambda.amazonaws.com]
Action: sts:AssumeRole
ManagedPolicyArns: # permission for writing to CloudWatch Logs
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment