AWS CLI ECR and ECS Cheat Sheet

AWS CLI ECR and ECS commands for repositories, image login and cleanup, clusters, services, task definitions, and tasks.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

ECR

Container registry workflows in Amazon ECR.

Get ECR login password

Generate a password token for Docker login.

bashANYawsecrdockerlogin
bash
aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin 123456789012.dkr.ecr.us-west-2.amazonaws.com

Common first step before pushing or pulling private ECR images.

Create an ECR repository

Create a private image repository.

bashANYawsecrrepository
bash
aws ecr create-repository --repository-name my-app

ECR repositories store container images and support lifecycle rules.

Describe repositories

List ECR repositories in the account.

bashANYawsecrrepository
bash
aws ecr describe-repositories

Useful for registry inventory scripts.

List images in a repository

Show image IDs in an ECR repository.

bashANYawsecrimages
bash
aws ecr list-images --repository-name my-app

Useful before cleanup or tagging operations.

Describe image details

Inspect pushed images, tags, sizes, and timestamps.

bashANYawsecrimages
bash
aws ecr describe-images --repository-name my-app

Useful for release inventory and stale image cleanup.

Delete one or more images

Remove images from a repository by tag or digest.

bashANYawsecrimagesdelete
bash
aws ecr batch-delete-image --repository-name my-app --image-ids imageTag=old-release

Useful in cleanup jobs and lifecycle tooling.

Set an ECR lifecycle policy

Attach a lifecycle policy document to a repository.

bashANYawsecrlifecycle
bash
aws ecr put-lifecycle-policy --repository-name my-app --lifecycle-policy-text file://lifecycle-policy.json

Automates cleanup of old images based on age or tag rules.

ECS Clusters and Services

Amazon ECS cluster, service, and task definition commands.

List ECS clusters

Show cluster ARNs in the account and region.

bashANYawsecsclusters
bash
aws ecs list-clusters

Useful for cluster inventory and discovery scripts.

Describe clusters

Inspect ECS cluster status and settings.

bashANYawsecsclusters
bash
aws ecs describe-clusters --clusters my-cluster

Useful for checking capacity providers and service connect settings.

Create an ECS cluster

Create a new ECS cluster.

bashANYawsecsclusterscreate
bash
aws ecs create-cluster --cluster-name my-cluster

Starting point for ECS service deployments.

List services in a cluster

Show ECS service ARNs for a cluster.

bashANYawsecsservices
bash
aws ecs list-services --cluster my-cluster

Useful for service inventory and automation loops.

Describe services

Inspect ECS service desired count, task definition, and deployment status.

bashANYawsecsservices
bash
aws ecs describe-services --cluster my-cluster --services my-service

Good first stop when troubleshooting ECS rollouts.

Force a new ECS deployment

Restart service tasks using the current task definition.

bashANYawsecsservicesdeploy
bash
aws ecs update-service --cluster my-cluster --service my-service --force-new-deployment

Useful after a new image tag is made available in-place.

Delete an ECS service

Remove an ECS service after scaling it down or forcing deletion.

bashANYawsecsservicesdelete
bash
aws ecs delete-service --cluster my-cluster --service my-service --force

Use with caution in production environments.

Task Definitions and Tasks

Register task definitions and run or inspect tasks.

Register a task definition

Create or update an ECS task definition revision from JSON.

bashANYawsecstask-definition
bash
aws ecs register-task-definition --cli-input-json file://taskdef.json

Task definitions describe containers, CPU, memory, networking, and IAM roles.

List task definitions

Show task definition family revisions.

bashANYawsecstask-definition
bash
aws ecs list-task-definitions --family-prefix my-app

Useful for release and revision inventory.

Run a one-off task

Start an ECS task without creating a service.

bashANYawsecstasksrun-task
bash
aws ecs run-task --cluster my-cluster --task-definition my-app:12 --launch-type FARGATE --network-configuration 'awsvpcConfiguration={subnets=[subnet-0123456789abcdef0],securityGroups=[sg-0123456789abcdef0],assignPublicIp=ENABLED}'

Useful for batch jobs, one-offs, and manual diagnostics.

List tasks

Show running or stopped tasks in a cluster.

bashANYawsecstasks
bash
aws ecs list-tasks --cluster my-cluster

Useful for operational inventory and loops.

Describe tasks

Inspect ECS task state, containers, and attachments.

bashANYawsecstasks
bash
aws ecs describe-tasks --cluster my-cluster --tasks arn:aws:ecs:us-west-2:123456789012:task/my-cluster/0123456789abcdef

Useful for finding stop reasons, ENIs, and exit codes.

Stop a task

Terminate a running ECS task.

bashANYawsecstasksstop
bash
aws ecs stop-task --cluster my-cluster --task arn:aws:ecs:us-west-2:123456789012:task/my-cluster/0123456789abcdef --reason 'manual stop'

Useful in incident response and manual cleanup.

Recommended next

No recommendations yet.