There are more AWS SDK examples available in the AWS Doc SDK Examples
Amazon ECS examples using AWS CLI
The following code examples show you how to perform actions and implement common scenarios by using the AWS Command Line Interface with Amazon ECS.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Actions
The following code example shows how to use capacity-provider-update.
- AWS CLI
-
Update the capacity provider in an ECS cluster
The following
update-capacity-providerexample shows how we can modify the parameters of the capacity provider in an ECS cluster.aws ecs update-capacity-provider \ --nameInfra-ECS-Cluster-ECS-project-update-cluster-d6bb6d5b-EC2CapacityProvider-3fIpdkLywwFt\ --auto-scaling-group-provider"managedScaling={status=DISABLED,targetCapacity=50,minimumScalingStepSize=2,maximumScalingStepSize=30,instanceWarmupPeriod=200},managedTerminationProtection=DISABLED,managedDraining=DISABLED"Output:
{ "capacityProvider": { "capacityProviderArn": "arn:aws:ecs:us-west-2:123456789012:capacity-provider/Infra-ECS-Cluster-ECS-project-update-cluster-d6bb6d5b-EC2CapacityProvider-3fIpdkLywwFt", "name": "Infra-ECS-Cluster-ECS-project-update-cluster-d6bb6d5b-EC2CapacityProvider-3fIpdkLywwFt", "status": "ACTIVE", "autoScalingGroupProvider": { "autoScalingGroupArn": "arn:aws:autoscaling:us-west-2:123456789012:autoScalingGroup:424941d1-b43f-4a17-adbb-08b6a6e397e1:autoScalingGroupName/Infra-ECS-Cluster-ECS-project-update-cluster-d6bb6d5b-ECSAutoScalingGroup-f44jrQHS2nRB", "managedScaling": { "status": "ENABLED", "targetCapacity": 100, "minimumScalingStepSize": 1, "maximumScalingStepSize": 10000, "instanceWarmupPeriod": 300 }, "managedTerminationProtection": "DISABLED", "managedDraining": "ENABLED" }, "updateStatus": "UPDATE_IN_PROGRESS", "tags": [] } }For more information on Capacity Provider, see Amazon ECS capacity providers for the EC2 launch type in the Amazon ECS Developer Guide.
-
For API details, see CapacityProviderUpdate
in AWS CLI Command Reference.
-
The following code example shows how to use create-capacity-provider.
- AWS CLI
-
To create a capacity provider
The following create-capacity-provider example creates a capacity provider that uses an Auto Scaling group named MyASG, has managed scaling and managed termination protection enabled. This configuration is used for Amazon ECS cluster auto scaling.
aws ecs create-capacity-provider \ --name"MyCapacityProvider"\ --auto-scaling-group-provider"autoScalingGroupArn=arn:aws:autoscaling:us-east-1:123456789012:autoScalingGroup:57ffcb94-11f0-4d6d-bf60-3bac5EXAMPLE:autoScalingGroupName/MyASG,managedScaling={status=ENABLED,targetCapacity=100},managedTerminationProtection=ENABLED"Output:
{ "capacityProvider": { "capacityProviderArn": "arn:aws:ecs:us-east-1:123456789012:capacity-provider/MyCapacityProvider", "name": "MyCapacityProvider", "status": "ACTIVE", "autoScalingGroupProvider": { "autoScalingGroupArn": "arn:aws:autoscaling:us-east-1:132456789012:autoScalingGroup:57ffcb94-11f0-4d6d-bf60-3bac5EXAMPLE:autoScalingGroupName/MyASG", "managedScaling": { "status": "ENABLED", "targetCapacity": 100, "minimumScalingStepSize": 1, "maximumScalingStepSize": 10000, "instanceWarmupPeriod": 300 }, "managedTerminationProtection": "ENABLED" }, "tags": [] }For more information, see Amazon ECS cluster auto scaling in the Amazon ECS Developer Guide.
-
For API details, see CreateCapacityProvider
in AWS CLI Command Reference.
-
The following code example shows how to use create-cluster.
- AWS CLI
-
Example 1: To create a new cluster
The following
create-clusterexample creates a cluster namedMyClusterand enables CloudWatch Container Insights with enhanced observability.aws ecs create-cluster \ --cluster-nameMyCluster\ --settingsname=containerInsights,value=enhancedOutput:
{ "cluster": { "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster", "clusterName": "MyCluster", "status": "ACTIVE", "registeredContainerInstancesCount": 0, "pendingTasksCount": 0, "runningTasksCount": 0, "activeServicesCount": 0, "statistics": [], "settings": [ { "name": "containerInsights", "value": "enhanced" } ], "tags": [] } }For more information, see Creating a Cluster in the Amazon ECS Developer Guide.
Example 2: To create a new cluster using capacity providers
The following
create-clusterexample creates a cluster and associates two existing capacity providers with it. Thecreate-capacity-providercommand is used to create a capacity provider. Specifying a default capacity provider strategy is optional, but recommended. In this example, we create a cluster namedMyClusterand associate theMyCapacityProvider1andMyCapacityProvider2capacity providers with it. A default capacity provider strategy is specified that spreads the tasks evenly across both capacity providers.aws ecs create-cluster \ --cluster-nameMyCluster\ --capacity-providersMyCapacityProvider1MyCapacityProvider2\ --default-capacity-provider-strategycapacityProvider=MyCapacityProvider1,weight=1capacityProvider=MyCapacityProvider2,weight=1Output:
{ "cluster": { "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster", "clusterName": "MyCluster", "status": "PROVISIONING", "registeredContainerInstancesCount": 0, "pendingTasksCount": 0, "runningTasksCount": 0, "activeServicesCount": 0, "statistics": [], "settings": [ { "name": "containerInsights", "value": "enabled" } ], "capacityProviders": [ "MyCapacityProvider1", "MyCapacityProvider2" ], "defaultCapacityProviderStrategy": [ { "capacityProvider": "MyCapacityProvider1", "weight": 1, "base": 0 }, { "capacityProvider": "MyCapacityProvider2", "weight": 1, "base": 0 } ], "attachments": [ { "id": "0fb0c8f4-6edd-4de1-9b09-17e470ee1918", "type": "asp", "status": "PRECREATED", "details": [ { "name": "capacityProviderName", "value": "MyCapacityProvider1" }, { "name": "scalingPlanName", "value": "ECSManagedAutoScalingPlan-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" } ] }, { "id": "ae592060-2382-4663-9476-b015c685593c", "type": "asp", "status": "PRECREATED", "details": [ { "name": "capacityProviderName", "value": "MyCapacityProvider2" }, { "name": "scalingPlanName", "value": "ECSManagedAutoScalingPlan-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222" } ] } ], "attachmentsStatus": "UPDATE_IN_PROGRESS" } }For more information, see Cluster capacity providers in the Amazon ECS Developer Guide.
Example 3: To create a new cluster with multiple tags
The following
create-clusterexample creates a cluster with multiple tags. For more information about adding tags using shorthand syntax, see Using Shorthand Syntax with the AWS Command Line Interface in the AWS CLI User Guide.aws ecs create-cluster \ --cluster-nameMyCluster\ --tagskey=key1,value=value1key=key2,value=value2Output:
{ "cluster": { "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster", "clusterName": "MyCluster", "status": "ACTIVE", "registeredContainerInstancesCount": 0, "pendingTasksCount": 0, "runningTasksCount": 0, "activeServicesCount": 0, "statistics": [], "tags": [ { "key": "key1", "value": "value1" }, { "key": "key2", "value": "value2" } ] } }For more information, see Creating a Cluster in the Amazon ECS Developer Guide.
-
For API details, see CreateCluster
in AWS CLI Command Reference.
-
The following code example shows how to use create-service.
- AWS CLI
-
Example 1: To create a service with a Fargate task
The following
create-serviceexample shows how to create a service using a Fargate task.aws ecs create-service \ --clusterMyCluster\ --service-nameMyService\ --task-definitionsample-fargate:1\ --desired-count2\ --launch-typeFARGATE\ --platform-versionLATEST\ --network-configuration 'awsvpcConfiguration={subnets=[subnet-12344321],securityGroups=[sg-12344321],assignPublicIp=ENABLED}' \ --tagskey=key1,value=value1key=key2,value=value2key=key3,value=value3Output:
{ "service": { "serviceArn": "arn:aws:ecs:us-west-2:123456789012:service/MyCluster/MyService", "serviceName": "MyService", "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster", "loadBalancers": [], "serviceRegistries": [], "status": "ACTIVE", "desiredCount": 2, "runningCount": 0, "pendingCount": 0, "launchType": "FARGATE", "platformVersion": "LATEST", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/sample-fargate:1", "deploymentConfiguration": { "maximumPercent": 200, "minimumHealthyPercent": 100 }, "deployments": [ { "id": "ecs-svc/1234567890123456789", "status": "PRIMARY", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/sample-fargate:1", "desiredCount": 2, "pendingCount": 0, "runningCount": 0, "createdAt": 1557119253.821, "updatedAt": 1557119253.821, "launchType": "FARGATE", "platformVersion": "1.3.0", "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-12344321" ], "securityGroups": [ "sg-12344321" ], "assignPublicIp": "ENABLED" } } } ], "roleArn": "arn:aws:iam::123456789012:role/aws-service-role/ecs.amazonaws.com/AWSServiceRoleForECS", "events": [], "createdAt": 1557119253.821, "placementConstraints": [], "placementStrategy": [], "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-12344321" ], "securityGroups": [ "sg-12344321" ], "assignPublicIp": "ENABLED" } }, "schedulingStrategy": "REPLICA", "tags": [ { "key": "key1", "value": "value1" }, { "key": "key2", "value": "value2" }, { "key": "key3", "value": "value3" } ], "enableECSManagedTags": false, "propagateTags": "NONE" } }For more information, see Creating a Service in the Amazon ECS Developer Guide.
Example 2: To create a service using the EC2 launch type
The following
create-serviceexample shows how to create a service calledecs-simple-servicewith a task that uses the EC2 launch type. The service uses thesleep360task definition and it maintains 1 instantiation of the task.aws ecs create-service \ --clusterMyCluster\ --service-nameecs-simple-service\ --task-definitionsleep360:2\ --desired-count1Output:
{ "service": { "serviceArn": "arn:aws:ecs:us-west-2:123456789012:service/MyCluster/ecs-simple-service", "serviceName": "ecs-simple-service", "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster", "loadBalancers": [], "serviceRegistries": [], "status": "ACTIVE", "desiredCount": 1, "runningCount": 0, "pendingCount": 0, "launchType": "EC2", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/sleep360:2", "deploymentConfiguration": { "maximumPercent": 200, "minimumHealthyPercent": 100 }, "deployments": [ { "id": "ecs-svc/1234567890123456789", "status": "PRIMARY", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/sleep360:2", "desiredCount": 1, "pendingCount": 0, "runningCount": 0, "createdAt": 1557206498.798, "updatedAt": 1557206498.798, "launchType": "EC2" } ], "events": [], "createdAt": 1557206498.798, "placementConstraints": [], "placementStrategy": [], "schedulingStrategy": "REPLICA", "enableECSManagedTags": false, "propagateTags": "NONE" } }For more information, see Creating a Service in the Amazon ECS Developer Guide.
Example 3: To create a service that uses an external deployment controller
The following
create-serviceexample creates a service that uses an external deployment controller.aws ecs create-service \ --clusterMyCluster\ --service-nameMyService\ --deployment-controllertype=EXTERNAL\ --desired-count1Output:
{ "service": { "serviceArn": "arn:aws:ecs:us-west-2:123456789012:service/MyCluster/MyService", "serviceName": "MyService", "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster", "loadBalancers": [], "serviceRegistries": [], "status": "ACTIVE", "desiredCount": 1, "runningCount": 0, "pendingCount": 0, "launchType": "EC2", "deploymentConfiguration": { "maximumPercent": 200, "minimumHealthyPercent": 100 }, "taskSets": [], "deployments": [], "roleArn": "arn:aws:iam::123456789012:role/aws-service-role/ecs.amazonaws.com/AWSServiceRoleForECS", "events": [], "createdAt": 1557128207.101, "placementConstraints": [], "placementStrategy": [], "schedulingStrategy": "REPLICA", "deploymentController": { "type": "EXTERNAL" }, "enableECSManagedTags": false, "propagateTags": "NONE" } }For more information, see Creating a Service in the Amazon ECS Developer Guide.
Example 4: To create a new service behind a load balancer
The following
create-serviceexample shows how to create a service that is behind a load balancer. You must have a load balancer configured in the same Region as your container instance. This example uses the--cli-input-jsonoption and a JSON input file calledecs-simple-service-elb.jsonwith the following content.aws ecs create-service \ --clusterMyCluster\ --service-nameecs-simple-service-elb\ --cli-input-jsonfile://ecs-simple-service-elb.jsonContents of
ecs-simple-service-elb.json:{ "serviceName": "ecs-simple-service-elb", "taskDefinition": "ecs-demo", "loadBalancers": [ { "loadBalancerName": "EC2Contai-EcsElast-123456789012", "containerName": "simple-demo", "containerPort": 80 } ], "desiredCount": 10, "role": "ecsServiceRole" }Output:
{ "service": { "status": "ACTIVE", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/ecs-demo:1", "pendingCount": 0, "loadBalancers": [ { "containerName": "ecs-demo", "containerPort": 80, "loadBalancerName": "EC2Contai-EcsElast-123456789012" } ], "roleArn": "arn:aws:iam::123456789012:role/ecsServiceRole", "desiredCount": 10, "serviceName": "ecs-simple-service-elb", "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster", "serviceArn": "arn:aws:ecs:us-west-2:123456789012:service/ecs-simple-service-elb", "deployments": [ { "status": "PRIMARY", "pendingCount": 0, "createdAt": 1428100239.123, "desiredCount": 10, "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/ecs-demo:1", "updatedAt": 1428100239.123, "id": "ecs-svc/1234567890123456789", "runningCount": 0 } ], "events": [], "runningCount": 0 } }For more information, see Use load balancing to distribute Amazon ECS service traffic in the Amazon ECS Developer Guide.
Example 5: To configure Amazon EBS volumes at service creation
The following
create-serviceexample shows how to configure Amazon EBS volumes for each task managed by the service. You must have an Amazon ECS infrastructure role configured with theAmazonECSInfrastructureRolePolicyForVolumesmanaged policy attached. You must specify a task definition with the same volume name as in thecreate-servicerequest. This example uses the--cli-input-jsonoption and a JSON input file calledecs-simple-service-ebs.jsonwith the following content.aws ecs create-service \ --cli-input-jsonfile://ecs-simple-service-ebs.jsonContents of
ecs-simple-service-ebs.json:{ "cluster": "mycluster", "taskDefinition": "mytaskdef", "serviceName": "ecs-simple-service-ebs", "desiredCount": 2, "launchType": "FARGATE", "networkConfiguration":{ "awsvpcConfiguration":{ "assignPublicIp": "ENABLED", "securityGroups": ["sg-12344321"], "subnets":["subnet-12344321"] } }, "volumeConfigurations": [ { "name": "myEbsVolume", "managedEBSVolume": { "roleArn":"arn:aws:iam::123456789012:role/ecsInfrastructureRole", "volumeType": "gp3", "sizeInGiB": 100, "iops": 3000, "throughput": 125, "filesystemType": "ext4" } } ] }Output:
{ "service": { "serviceArn": "arn:aws:ecs:us-west-2:123456789012:service/mycluster/ecs-simple-service-ebs", "serviceName": "ecs-simple-service-ebs", "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/mycluster", "loadBalancers": [], "serviceRegistries": [], "status": "ACTIVE", "desiredCount": 2, "runningCount": 0, "pendingCount": 0, "launchType": "EC2", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/mytaskdef:3", "deploymentConfiguration": { "deploymentCircuitBreaker": { "enable": false, "rollback": false }, "maximumPercent": 200, "minimumHealthyPercent": 100 }, "deployments": [ { "id": "ecs-svc/7851020056849183687", "status": "PRIMARY", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/mytaskdef:3", "desiredCount": 0, "pendingCount": 0, "runningCount": 0, "failedTasks": 0, "createdAt": "2025-01-21T11:32:38.034000-06:00", "updatedAt": "2025-01-21T11:32:38.034000-06:00", "launchType": "EC2", "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-12344321" ], "securityGroups": [ "sg-12344321" ], "assignPublicIp": "DISABLED" } }, "rolloutState": "IN_PROGRESS", "rolloutStateReason": "ECS deployment ecs-svc/7851020056849183687 in progress.", "volumeConfigurations": [ { "name": "myEBSVolume", "managedEBSVolume": { "volumeType": "gp3", "sizeInGiB": 100, "iops": 3000, "throughput": 125, "roleArn": "arn:aws:iam::123456789012:role/ecsInfrastructureRole", "filesystemType": "ext4" } } ] } ], "roleArn": "arn:aws:iam::123456789012:role/aws-service-role/ecs.amazonaws.com/AWSServiceRoleForECS", "events": [], "createdAt": "2025-01-21T11:32:38.034000-06:00", "placementConstraints": [], "placementStrategy": [], "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-12344321" ], "securityGroups": [ "sg-12344321" ], "assignPublicIp": "DISABLED" } }, "healthCheckGracePeriodSeconds": 0, "schedulingStrategy": "REPLICA", "deploymentController": { "type": "ECS" }, "createdBy": "arn:aws:iam::123456789012:user/AIDACKCEVSQ6C2EXAMPLE", "enableECSManagedTags": false, "propagateTags": "NONE", "enableExecuteCommand": false, "availabilityZoneRebalancing": "DISABLED" } }For more information, see Use Amazon EBS volumes with Amazon ECS in the Amazon ECS Developer Guide.
-
For API details, see CreateService
in AWS CLI Command Reference.
-
The following code example shows how to use create-task-set.
- AWS CLI
-
To create a task set
The following
create-task-setexample creates a task set in a service that uses an external deployment controller.aws ecs create-task-set \ --clusterMyCluster\ --serviceMyService\ --task-definitionMyTaskDefinition:2\ --network-configuration"awsvpcConfiguration={subnets=[subnet-12344321],securityGroups=[sg-12344321]}"Output:
{ "taskSet": { "id": "ecs-svc/1234567890123456789", "taskSetArn": "arn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789", "status": "ACTIVE", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/MyTaskDefinition:2", "computedDesiredCount": 0, "pendingCount": 0, "runningCount": 0, "createdAt": 1557128360.711, "updatedAt": 1557128360.711, "launchType": "EC2", "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-12344321" ], "securityGroups": [ "sg-12344321" ], "assignPublicIp": "DISABLED" } }, "loadBalancers": [], "serviceRegistries": [], "scale": { "value": 0.0, "unit": "PERCENT" }, "stabilityStatus": "STABILIZING", "stabilityStatusAt": 1557128360.711 } }-
For API details, see CreateTaskSet
in AWS CLI Command Reference.
-
The following code example shows how to use delete-account-setting.
- AWS CLI
-
To delete the account settings for a specific IAM user or IAM role
The following example
delete-account-settingdeletes the account settings for the specific IAM user or IAM role.aws ecs delete-account-setting \ --nameserviceLongArnFormat\ --principal-arnarn:aws:iam::123456789012:user/MyUserOutput:
{ "setting": { "name": "serviceLongArnFormat", "value": "enabled", "principalArn": "arn:aws:iam::123456789012:user/MyUser" } }For more information, see Amazon Resource Names (ARNs) and IDs in the Amazon ECS Developer Guide.
-
For API details, see DeleteAccountSetting
in AWS CLI Command Reference.
-
The following code example shows how to use delete-attributes.
- AWS CLI
-
To delete one or more custom attributes from an Amazon ECS resource
The following
delete-attributesdeletes an attribute with the namestackfrom a container instance.aws ecs delete-attributes \ --attributesname=stack,targetId=arn:aws:ecs:us-west-2:130757420319:container-instance/1c3be8ed-df30-47b4-8f1e-6e68ebd01f34Output:
{ "attributes": [ { "name": "stack", "targetId": "arn:aws:ecs:us-west-2:130757420319:container-instance/1c3be8ed-df30-47b4-8f1e-6e68ebd01f34", "value": "production" } ] }-
For API details, see DeleteAttributes
in AWS CLI Command Reference.
-
The following code example shows how to use delete-capacity-provider.
- AWS CLI
-
Example 1: To delete a capacity provider using the Amazon Resource Name (ARN)
The following
delete-capacity-providerexample deletes a capacity provider by specifying the Amazon Resource Name (ARN) of the capacity provider. The ARN as well as the status of the capacity provider deletion can be retrieved using thedescribe-capacity-providerscommand.aws ecs delete-capacity-provider \ --capacity-providerarn:aws:ecs:us-west-2:123456789012:capacity-provider/ExampleCapacityProviderOutput:
{ "capacityProvider": { "capacityProviderArn": "arn:aws:ecs:us-west-2:123456789012:capacity-provider/ExampleCapacityProvider", "name": "ExampleCapacityProvider", "status": "ACTIVE", "autoScalingGroupProvider": { "autoScalingGroupArn": "arn:aws:autoscaling:us-west-2:123456789012:autoScalingGroup:a1b2c3d4-5678-90ab-cdef-EXAMPLE11111:autoScalingGroupName/MyAutoScalingGroup", "managedScaling": { "status": "ENABLED", "targetCapacity": 100, "minimumScalingStepSize": 1, "maximumScalingStepSize": 10000 }, "managedTerminationProtection": "DISABLED" }, "updateStatus": "DELETE_IN_PROGRESS", "tags": [] } }For more information, see Cluster capacity providers in the Amazon ECS Developer Guide.
Example 2: To delete a capacity provider using the name
The following
delete-capacity-providerexample deletes a capacity provider by specifying the short name of the capacity provider. The short name as well as the status of the capacity provider deletion can be retrieved using thedescribe-capacity-providerscommand.aws ecs delete-capacity-provider \ --capacity-providerExampleCapacityProviderOutput:
{ "capacityProvider": { "capacityProviderArn": "arn:aws:ecs:us-west-2:123456789012:capacity-provider/ExampleCapacityProvider", "name": "ExampleCapacityProvider", "status": "ACTIVE", "autoScalingGroupProvider": { "autoScalingGroupArn": "arn:aws:autoscaling:us-west-2:123456789012:autoScalingGroup:a1b2c3d4-5678-90ab-cdef-EXAMPLE11111:autoScalingGroupName/MyAutoScalingGroup", "managedScaling": { "status": "ENABLED", "targetCapacity": 100, "minimumScalingStepSize": 1, "maximumScalingStepSize": 10000 }, "managedTerminationProtection": "DISABLED" }, "updateStatus": "DELETE_IN_PROGRESS", "tags": [] } }For more information, see Cluster capacity providers in the Amazon ECS Developer Guide.
-
For API details, see DeleteCapacityProvider
in AWS CLI Command Reference.
-
The following code example shows how to use delete-cluster.
- AWS CLI
-
To delete an empty cluster
The following
delete-clusterexample deletes the specified empty cluster.aws ecs delete-cluster --clusterMyClusterOutput:
{ "cluster": { "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster", "status": "INACTIVE", "clusterName": "MyCluster", "registeredContainerInstancesCount": 0, "pendingTasksCount": 0, "runningTasksCount": 0, "activeServicesCount": 0 "statistics": [], "tags": [] } }For more information, see Deleting a Cluster in the Amazon ECS Developer Guide.
-
For API details, see DeleteCluster
in AWS CLI Command Reference.
-
The following code example shows how to use delete-service.
- AWS CLI
-
To delete a service
The following
ecs delete-serviceexample deletes the specified service from a cluster. You can include the--forceparameter to delete a service even if it has not been scaled to zero tasks.aws ecs delete-service --clusterMyCluster--serviceMyService1--forceFor more information, see Deleting a Service in the Amazon ECS Developer Guide.
-
For API details, see DeleteService
in AWS CLI Command Reference.
-
The following code example shows how to use delete-task-definitions.
- AWS CLI
-
To delete a task definition
The following
delete-task-definitionsexample deletes an INACTIVE task definition.aws ecs delete-task-definitions \ --task-definitioncurltest:1Output:
{ "taskDefinitions": [ { "taskDefinitionArn": "arn:aws:ecs:us-east-1:123456789012:task-definition/curltest:1", "containerDefinitions": [ { "name": "ctest", "image": "mreferre/eksutils", "cpu": 0, "portMappings": [], "essential": true, "entryPoint": [ "sh", "-c" ], "command": [ "curl ${ECS_CONTAINER_METADATA_URI_V4}/task" ], "environment": [], "mountPoints": [], "volumesFrom": [], "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-create-group": "true", "awslogs-group": "/ecs/curltest", "awslogs-region": "us-east-1", "awslogs-stream-prefix": "ecs" } } } ], "family": "curltest", "taskRoleArn": "arn:aws:iam::123456789012:role/ecsTaskExecutionRole", "executionRoleArn": "arn:aws:iam::123456789012:role/ecsTaskExecutionRole", "networkMode": "awsvpc", "revision": 1, "volumes": [], "status": "DELETE_IN_PROGRESS", "compatibilities": [ "EC2", "FARGATE" ], "requiresCompatibilities": [ "FARGATE" ], "cpu": "256", "memory": "512", "registeredAt": "2021-09-10T12:56:24.704000+00:00", "deregisteredAt": "2023-03-14T15:20:59.419000+00:00", "registeredBy": "arn:aws:sts::123456789012:assumed-role/Admin/jdoe" } ], "failures": [] }For more information, see Amazon ECS Task Definitions in the Amazon ECS Developer Guide.
-
For API details, see DeleteTaskDefinitions
in AWS CLI Command Reference.
-
The following code example shows how to use delete-task-set.
- AWS CLI
-
To delete a task set
The following
delete-task-setexample shows how to delete a task set. You can include the--forceparameter to delete a task set even if it has not been scaled to zero.aws ecs delete-task-set \ --clusterMyCluster\ --serviceMyService\ --task-setarn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789\ --forceOutput:
{ "taskSet": { "id": "ecs-svc/1234567890123456789", "taskSetArn": "arn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789", "status": "DRAINING", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/sample-fargate:2", "computedDesiredCount": 0, "pendingCount": 0, "runningCount": 0, "createdAt": 1557130260.276, "updatedAt": 1557130290.707, "launchType": "EC2", "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-12345678" ], "securityGroups": [ "sg-12345678" ], "assignPublicIp": "DISABLED" } }, "loadBalancers": [], "serviceRegistries": [], "scale": { "value": 0.0, "unit": "PERCENT" }, "stabilityStatus": "STABILIZING", "stabilityStatusAt": 1557130290.707 } }-
For API details, see DeleteTaskSet
in AWS CLI Command Reference.
-
The following code example shows how to use deregister-container-instance.
- AWS CLI
-
To deregister a container instance from a cluster
The following