Open the SAM template (
sam-app/template.yaml) in your project and add the following lines to the HelloWorldFunction properties section.
AutoPublishAlias: live DeploymentPreference: Type: Canary10Percent5Minutes
It should look like this:
PLEASE CHECK THE CORRECT INDENTATION, IT IS VERY IMPORTANT IN YAML FORMAT.
For this workshop, we are using the Canary10Percent5Minutes strategy, which means that traffic is shifted in two increments. In the first increment, only 10% of the traffic is shifted to the new Lambda version, and after 5 minutes, the remaining 90% is shifted. There are other deployment strategies you can choose in CodeDeploy:
The Linear strategy means that traffic is shifted in equal increments with an equal number of time interval between each increment.
Run the following command on your terminal:
cd ~/environment/sam-app sam validate
If the template is correct, you will see
template.yaml is a valid SAM Template. If you see an error, then you likely have an indentation issue on the YAML file. Double check and make sure it matches the screenshot shown above.
In the terminal, run the following commands from the root directory of your
git add . git commit -m "Canary deployments with SAM" git push