Skip to content

Instantly share code, notes, and snippets.

@alexcasalboni
Last active October 2, 2019 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexcasalboni/7dcc74da977b0e531638b99dbf8899c8 to your computer and use it in GitHub Desktop.
Save alexcasalboni/7dcc74da977b0e531638b99dbf8899c8 to your computer and use it in GitHub Desktop.
AWS CodeDeploy - Lambda pre-traffic hook (YAML)
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
myFunctionToBeDeployed:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
AutoPublishAlias: live
DeploymentPreference:
Type: Linear10PercentEvery1Minute
Hooks:
PreTraffic: !Ref preTrafficHook
# ...
# all the other properties here
# ...
preTrafficHook:
Type: AWS::Serverless::Function
Properties:
Handler: preTrafficHook.handler
Runtime: nodejs8.10
DeploymentPreference:
Enabled: false
Environment:
Variables:
NewVersion: !Ref myFunctionToBeDeployed.Version
Policies:
- Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- codedeploy:PutLifecycleEventHookExecutionStatus
Resource: !Sub 'arn:aws:codedeploy:${AWS::Region}:${AWS::AccountId}:deploymentgroup:${ServerlessDeploymentApplication}/*'
- Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource: !Ref myFunctionToBeDeployed.Version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment