- Ensure the build creates an
imagedefinitions.jsonartifact required by ECS. - Add a Deploy stage to the login microservice pipeline that uses the Amazon ECS deploy action.
- Verify the new deployment in the ECS console and confirm healthy tasks behind the load balancer.
- You already have a working login microservice repository and a CodePipeline with Source and Build stages.
- You have an ECS cluster and service (task definition with a container name) configured to run the login microservice.
- You have access to the AWS Console and Cloud9 (or any editor) to update files and push commits.
- In the AWS Console, open Cloud9, close open files, and open the
buildspec.ymlfile.

imagedefinitions.json is required
- Amazon ECS’s CodePipeline action expects
imagedefinitions.jsonin the Build artifact. This file maps the container name from your task definition to the pushed ECR image URI so ECS can update the service with the new image.
imagedefinitions.json:
imagedefinitions.json creation to buildspec.yml
- Add (or update) a
post_buildstep that writesimagedefinitions.jsonusing the built image URI (typically available in an environment variable such as$IMAGE_URI).
buildspec.yml:
- Replace
login-app-containerwith the exact container name from your ECS task definition. - Save the file.
- Make a minor UI tweak to confirm deployment behavior. For example, ensure the login button text shows “Login” and add basic styling.
master with your branch name if different.)
Open CodePipeline and add the Deploy stage
- In the AWS Console, go to CodePipeline and locate the
login-page-microservicepipeline.

- You’ll notice this pipeline currently has Source and Build stages only. Wait for the running execution to finish, then click Edit.

- Click Add stage and name it
Deploy. - In the Deploy stage, click Add action group → Add action.
- Set Action provider to
Amazon ECS. - For Input artifact, choose the Build artifact (often named something like
BuildArtifactorAppBuildArtifact) — this artifact must containimagedefinitions.json. Do not select the Source artifact. - Select the target ECS cluster (for example,
production-cluster) and the service (for example,login-app-microservice). - Set the Image definitions file name to
imagedefinitions.json. - Click Done and Save the pipeline.
- Back in the pipeline, click Release change to start a new execution. Leave defaults and confirm.
- If the deploy action fails, inspect the action execution details to find the cause (most commonly the pipeline cannot locate
imagedefinitions.json).

Verify action details
- Inspect a successful pipeline’s Deploy action to confirm it uses the Build artifact and points to the correct cluster/service and file name.

- After releasing a change, the pipeline should move from Build to Deploy.

- Open the ECS console, navigate to the login service, and check the Deployments tab for the new deployment initiated by CodePipeline.

- Wait for the new task to reach healthy status. Inspect the target group behind the load balancer to view health checks and target registration.

- Copy the load balancer DNS into a browser and refresh. During a rolling deployment you may observe requests temporarily split between the old and new tasks until the older task is drained. This is expected behavior for healthy rolling releases.
- To temporarily prevent automatic deployments, disable the transition from Build to Deploy in CodePipeline. Re-enable it later and provide a reason in the dialog.
When adding the ECS Deploy action, always select the Build artifact as the input and ensure
imagedefinitions.json is created in the Build stage. This is the most common cause of ECS deploy failures in CodePipeline.- Optionally commit simultaneous updates for the login microservice and other microservices (like the product app) to confirm both pipelines build and deploy independently.
- Review IAM roles used by CodePipeline, CodeBuild, and ECS to verify least-privilege access for automated deployments.
- AWS CodePipeline documentation
- Amazon ECS deployment types and options
- Buildspec reference for AWS CodeBuild
- Amazon ECR user guide