CI/CD for AWS ECS
Build and push a Docker image to AWS ECR and trigger an AWS ECS deployment.
Use template →1env:
2 ROLE_ARN: arn:aws:iam::$AWS_ACCOUNT_ID:role/my-role
3 IMAGE_NAME: $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/my-repo
4 CLUSTER: my-cluster
5 SERVICE: my-service
6 AWS_PAGER: "" # Disable AWS CLI pagination in CI
7
8steps:
9 - label: ":ecr: Push image"
10 key: "push-image"
11 command: |
12 docker build --platform=linux/amd64 -t $IMAGE_NAME:latest .
13 docker push $IMAGE_NAME:latest
14 plugins:
15 - aws-assume-role-with-web-identity#v1.0.0:
16 role_arn: $ROLE_ARN
17 - ecr#v2.8.0:
18 login: true
19
20 - label: ":ecs: Deploy service"
21 depends_on: "push-image"
22 timeout_in_minutes: 5
23 command: |
24 aws ecs update-service --cluster $CLUSTER --service $SERVICE --force-new-deployment
25 aws ecs wait services-stable --cluster $CLUSTER --service $SERVICE
26 plugins:
27 - aws-assume-role-with-web-identity#v1.0.0:
28 role_arn: $ROLE_ARN
- Use cases
- Continuous deployment, Continuous integration
- Platforms
- AWS
CI/CD for AWS ECS
Build and push a Docker image to AWS ECR and trigger an AWS ECS deployment.
Use template →CI/CD for AWS ECS
This templates gives you a continuous deployment (CD) pipeline that builds and deploys the latest version of an AWS ECR hosted Docker image to AWS ECS.
At a glance:
- For Docker applications
- Requires AWS CLI
- Uses the AWS Assume Role plugin to access AWS credentials
- Uses ECR for hosting images
- Deploys to AWS ECS
How it works
This template:
- Builds a Docker image
- Assumes an AWS role using the AWS Assume Role with Web Identity plugin.
- Pushes a tagged Docker image to an AWS ECR registry.
- Deploys an AWS ECS service with the latest image.
- Waits for the AWS ECS service to stabilize.
Next steps
After you select Use template, you’ll:
- Connect the Git repository with your project.
- Using an AWS IAM role with the appropriate ECR and ECS policies, replace the placeholder
ROLE_ARN
in the pipeline definition. - Replace the placeholder
IMAGE_NAME
,SERVICE
andCLUSTER
in the pipeline definition to match your project. - Configure the compute—run locally, on-premises, or in the cloud.
- Run the pipeline.
You can then play around with the pipeline settings. For example, run the pipeline locally while you iterate on the definition or set a schedule to trigger a nightly build.
If you need help, please check our documentation, raise an issue , or reach out to support.