This repository is a modified version of CodeStar Express.js Lambda project which includes PreTraffic hook. Just copy following files to your AWS CodeStar project.
preTrafficHook.js
template.yml
Once you push the code, it should automatically get built and deployed by AWS CodePipeline.
You might run into issue when deploying new code since your CloudFormation does not have permission to perform some operations. You will need to add proper permission to CloudFormation's IAM role. You can find the name of CloudFormation's IAM role in Stack info tab in AWS CloudFormation console. Go to that IAM Role and attach following policies:
IAMFullAccess
AWSCodeDeployFullAccess
The PreTraffic hook checks that GET /
returns 200. You can simulate failure by modifying your app.js
to return 500 instead.
res.status(500).send('Something broke!')
The deployment should fail due to validation by PreTraffic hook.
Once the deployment succeeded, you can try other types of deployment preference. In template.yml
, you can see other types which got commented out. Try one of those types and see the result in CodeDeploy console.