Enterprise-CMCS / macpro-quickstart-serverless

Other
18 stars 14 forks source link

integrate CodeDeploy with QuickStart app-api create lambda function #572

Closed leslie-corbalt closed 1 year ago

leslie-corbalt commented 2 years ago

Purpose

To make deployments more robust, the QuickStart can deploy a lambda function with AWS CodeDeploy. This enables traffic to shift in increments to the new version, and to run smoke-tests before and after traffic-shifting to validate the new version. AWS CodeDeploy stops a deployment if a cloudwatch alarm is trigger or a smoke-test fails and automatically rolls back the deployment: CodeDeploy shifts all traffic to the old version.

Tested: I verified 3 deploys: preHook fails => deploy rolled back preHook succeeds and postHook fails => deploy rolled back preHook and postHook succeed => deploy succeeds

verified warmup: verified that preHook and postHook are not kept warm

Not tested: I did not test with CloudWatch alarms, since I don't have any set up. I did not create an SNS topic and post deploy results to the topic.

Linked Issues to Close

https://jiraent.cms.gov/browse/CMCSMACD-592

Approach

Configured 1 lambda function in 1 service with the serverless-canary-deployment plugin. service: app-api function: create.js added the validation functions (as a sample): preCreate and postCreate in hooks.js

Learning

I learned about QuickStart and AWS CodeDeploy by reading and experimenting. Here is a doc of the big picture.

Assorted Notes/Considerations

This code is not meant to be merged, since it only configures CodeDeploy on 1 function. The goal would be to apply this plugin to all functions for each service with functions. This code is so you review the idea of using AWS CodeDeploy.

Pull Request Creator Checklist

Pull Request Reviewer/Assignee Checklist