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.

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.
imagedefinitions.json. Click Done and then Save the pipeline.

2) Update the buildspec so CodeBuild produces the required artifact
CodePipeline’s ECS deploy action consumes an artifact namedimagedefinitions.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.jsonartifact, - replace a placeholder in the ECS task definition, and
- register an updated task definition (optional but useful).
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:
What to look for in CodeBuild logs
In the Build stage logs you should see entries that indicate theimagedefinitions.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.


5) Inspect the imagedefinitions.json artifact and commits
Theimagedefinitions.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:

Quick reference
Summary
- Add a Deploy stage in CodePipeline and select Amazon ECS as the provider.
- Update
buildspec.ymlso CodeBuild builds/pushes the image and emitsimagedefinitions.json. - Commit and push changes to your source repository to trigger an automated pipeline run.
- Inspect CodeBuild logs, the
imagedefinitions.jsonartifact 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.
- AWS CodePipeline Documentation
- Amazon ECS Deploy Action in CodePipeline
- AWS CodeBuild Buildspec Reference