Tutorial: Deploy an Amazon ECS service with a validation test - Amazon CodeDeploy
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

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, Amazon Lambda pricing, and Amazon CloudWatch pricing.