Tutorial: Deploy an Amazon ECS service with a validation test
In this tutorial, you learn how to use a Lambda function to validate part of the deployment of an updated Amazon ECS application. This tutorial uses the CodeDeploy application, CodeDeploy deployment group, and the Amazon ECS application you used in Tutorial: Deploy an application into Amazon ECS. Complete that tutorial before starting this one.
To add validation test, you first implement the test in a Lambda function. Next, in your deployment AppSpec file, you specify the Lambda function for the lifecycle hook you want to test. If a validation test fails, the deployment stops, is rolled back, and marked failed. If the test succeeds, the deployment continues to the next deployment lifecycle event or hook.
During an Amazon ECS deployment with validation tests, CodeDeploy uses a load balancer that is configured with two target groups: one production traffic listener and one test traffic listener. The following diagram shows how the load balancer, production and test listeners, target groups, and your Amazon ECS application are related before the deployment starts. This tutorial uses an Application Load Balancer. You can also use a Network Load Balancer.
During an Amazon ECS deployment, there are five lifecycle hooks for testing. This tutorial
implements one test during the third lifecycle deployment hook,
AfterAllowTestTraffic
. For more information, see List of lifecycle
event hooks for an Amazon ECS deployment. After a successful
deployment, the production traffic listener serves traffic to your new replacment task set and
the original task set is terminated. The following diagram shows how your resources are related
after a successful deployment. For more information, see What happens during an Amazon ECS
deployment.
Note
Completing this tutorial might result in charges to your Amazon account. These include
possible charges for CodeDeploy, Amazon Lambda, and CloudWatch. For more information, see Amazon CodeDeploy pricing
Topics
- Prerequisites
- Step 1: Create a test listener
- Step 2: Update your Amazon ECS application
- Step 3: Create a lifecycle hook Lambda function
- Step 4: Update your AppSpec file
- Step 5: Use the CodeDeploy console to deploy your Amazon ECS service
- Step 6: View your Lambda hook function output in CloudWatch Logs
- Step 7: Clean up