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
Get ECR login password
aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin 123456789012.dkr.ecr.us-west-2.amazonaws.com

# Generate a password token for Docker login.

Create an ECR repository
aws ecr create-repository --repository-name my-app

# Create a private image repository.

Describe repositories
aws ecr describe-repositories

# List ECR repositories in the account.

List images in a repository
aws ecr list-images --repository-name my-app

# Show image IDs in an ECR repository.

Describe image details
aws ecr describe-images --repository-name my-app

# Inspect pushed images, tags, sizes, and timestamps.

Delete one or more images
aws ecr batch-delete-image --repository-name my-app --image-ids imageTag=old-release

# Remove images from a repository by tag or digest.

Set an ECR lifecycle policy
aws ecr put-lifecycle-policy --repository-name my-app --lifecycle-policy-text file://lifecycle-policy.json

# Attach a lifecycle policy document to a repository.

## ECS Clusters and Services
List ECS clusters
aws ecs list-clusters

# Show cluster ARNs in the account and region.

Describe clusters
aws ecs describe-clusters --clusters my-cluster

# Inspect ECS cluster status and settings.

Create an ECS cluster
aws ecs create-cluster --cluster-name my-cluster

# Create a new ECS cluster.

List services in a cluster
aws ecs list-services --cluster my-cluster

# Show ECS service ARNs for a cluster.

Describe services
aws ecs describe-services --cluster my-cluster --services my-service

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

Force a new ECS deployment
aws ecs update-service --cluster my-cluster --service my-service --force-new-deployment

# Restart service tasks using the current task definition.

Delete an ECS service
aws ecs delete-service --cluster my-cluster --service my-service --force

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

## Task Definitions and Tasks
Register a task definition
aws ecs register-task-definition --cli-input-json file://taskdef.json

# Create or update an ECS task definition revision from JSON.

List task definitions
aws ecs list-task-definitions --family-prefix my-app

# Show task definition family revisions.

Run a one-off task
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}'

# Start an ECS task without creating a service.

List tasks
aws ecs list-tasks --cluster my-cluster

# Show running or stopped tasks in a cluster.

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

# Inspect ECS task state, containers, and attachments.

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

# Terminate a running ECS task.

Recommended next

No recommendations yet.