Skip to main content
Welcome back. In this guide we’ll extend the pipeline we built earlier by adding a Deploy stage to automatically push new images to an ECS service. The flow covered here: update the pipeline, ensure CodeBuild produces the required artifact, and confirm ECS performs a rolling deployment.

1) Add a Deploy stage in CodePipeline

Edit the pipeline in the CodePipeline console and add a new stage after Build:
  • Click Add stage and name it Deploy.
  • Inside the Deploy stage, click Add action group and provide an action name (for example, Deploy).
  • For Provider select Amazon ECS — do not select the ECR Blue/Green option because this tutorial uses rolling deployments (ECS rolling updates).
  • For Input artifacts, pick the artifact produced by the Build stage.
  • Choose the Production cluster and the ECS service to deploy.
The image shows a configuration screen for an AWS CodePipeline, with settings for ECS deployment, including fields for action name, region, input artifacts, cluster name, and service name.
When selecting the provider, pick Amazon ECS (rolling deployments). Choosing ECR Blue/Green will switch CodePipeline to a different deployment model that requires a different setup.
In the action configuration, set the Image Definitions filename to imagedefinitions.json. Click Done and then Save the pipeline.
The image displays an AWS CodePipeline configuration screen, showing sections for editing pipeline properties, variables, triggers, and source. The pipeline type is listed as V2 with an execution mode of QUEUED.

2) Update the buildspec so CodeBuild produces the required artifact

CodePipeline’s ECS deploy action consumes an artifact named imagedefinitions.json. Update the buildspec.yml in your Cloud9 (or local) editor to:
  • authenticate to ECR,
  • build and push the image (tagged by commit hash),
  • write the imagedefinitions.json artifact,
  • replace a placeholder in the ECS task definition, and
  • register an updated task definition (optional but useful).
Use this concise buildspec:
The ECS deploy action expects imagedefinitions.json to be an array of objects with name (container name) and imageUri (image URI including the tag). Example: [{"name":"your-container-name","imageUri":"<registry>/<repo>:<tag>"}].

3) Commit, push, and validate the pipeline run

After editing your app (for example, changing the login page text), commit and push the changes to trigger the pipeline:
CodePipeline will automatically start a new execution and progress through Source → Build → Deploy.
The image shows an AWS CodePipeline interface for a project named "crypto-app," displaying two stages: "Source," which has succeeded, and "Build," which is in progress.

What to look for in CodeBuild logs

In the Build stage logs you should see entries that indicate the imagedefinitions.json file is created and the task definition is registered, similar to:

4) Observe ECS deployment and health

Once the Deploy stage starts, ECS will create a new deployment and start tasks using the pushed image. Monitor the ECS console for task activity, health checks, and load balancer status.
This image shows the AWS Elastic Container Service (ECS) console displaying details for a crypto-app, including task information and container details.
The image is a screenshot of the Amazon Elastic Container Service (ECS) console, showing the health and metrics of a service named "crypto-app" within a production cluster. The service is active, with tasks running and a load balancer in place.
The image shows the Amazon Elastic Container Service (ECS) interface with a focus on deployments for a service named "crypto-app." It lists deployment details, statuses, events, and associated tasks.
Open the Tasks view to confirm new tasks are launching and old ones are draining. ECS’s rolling update strategy will replace tasks gradually and — if configured — automatically roll back failed deployments. After deployment completes, retrieve the load balancer DNS and verify the app (for example, confirm the updated login text).

5) Inspect the imagedefinitions.json artifact and commits

The imagedefinitions.json produced by the Build stage is stored in the CodePipeline artifact S3 bucket. You can download the artifact from the pipeline’s artifacts to inspect it. The file contains entries with container names and the image URIs (including commit tag). Example:
Validate the commit hash in CodeCommit by viewing the repository’s commits:
The image shows the AWS CodeCommit interface displaying a list of commits for the "aws-microservice-project" repository. It includes details like commit IDs, messages, dates, and author information.

Quick reference

Summary

  • Add a Deploy stage in CodePipeline and select Amazon ECS as the provider.
  • Update buildspec.yml so CodeBuild builds/pushes the image and emits imagedefinitions.json.
  • Commit and push changes to your source repository to trigger an automated pipeline run.
  • Inspect CodeBuild logs, the imagedefinitions.json artifact in S3, and ECS console to confirm rolling deployment.
  • The full flow is automated: push → build → deploy, with ECS managing rolling updates and optional rollback.
Further reading and references: Congratulations — you now have an end-to-end automated deployment pipeline for your crypto-app using CodeCommit, CodeBuild, CodePipeline, ECR, and ECS.

Watch Video

Practice Lab