AWS Fargate and ECS Suspension

Amazon Elastic Container Service (Amazon ECS) is a fully managed container orchestration service. This service helps you easily deploy, manage, and scale containerized applications. Amazon ECS leverages AWS Fargates serverless technology to deliver autonomous container operations.

An Amazon ECS cluster is a logical grouping of tasks or services. You can register one or more Amazon EC2 instances (also called container instances) with your cluster to run tasks on them. Or, you can use the serverless infrastructure that Fargate provides to run tasks. When your tasks are run on Fargate, your cluster resources are also managed by Fargate.

Task definition can be thought of as a blueprint for the application. To prepare to launch an application, we need a task definition written in JSON format.

Table of Contents

Task

The Task is the instantiation of the task definition in the cluster. The number of tasks can be defined in the service definition.

Tasks can be viewed by clicking anywhere on the resource and then selecting the Tasks Tab. Each task will be displayed on this tab.

Click on a task to view its details and tags. Use the Back button to return to the previous screen.


Service

The Service is responsible for running and maintaining the desired number of tasks that are running in the cluster Container Instances (EC2 instances).

Service details can be viewed by clicking anywhere on the resource and then selecting the Details Tab.

Container Instances (EC2 instances)

If we do not want to use the serverless infrastructure we can provide EC2 instance configuration to use, ECS spawns them in an ASG, and the services/tasks are deployed on these instances.


Launch Models

If we do not want to use the serverless infrastructure, we can provide EC2 instance configuration to use, ECS spawns them in an ASG, and the services/tasks are deployed on these instances Launch Models.



Amazon ECS provides us three launch models for container orchestration:

  • Fargate: This is a serverless infrastructure option. The instances layer is abstracted and taken care of by Amazon itself.

  • EC2 Launch Model: In this launch model, we choose the number and type of EC2 instances to be used and are responsible for maintaining the servers. Amazon ECS only orchestrates containers on these servers.

     

  • AWS outpost/External: We can use external servers and Amazon ECS will take care of container orchestration.


A combination of launch models can be used for a task in the Amazon ECS cluster (i.e A cluster can have multiple services running on Fargate./EC2 instances and AWS outpost).

Amazon ECS Costing

The cost of Amazon ECS is dependent on the launch model we use for a service.

There is no dedicated pricing for Amazon ECS service.

Fargate: Since the Fargate is a serverless infrastructure model and there being no EC2 instance provisioned/reserved, the pricing is based on the number of resources that a task utilizes (combination of vCPU and memory).

EC2 Launch Model: In this model, since we have EC2 instances provisioned, we are charged for the EC2 instances and not based on tasks/services.

Amazon ECS pricing: https://aws.amazon.com/ecs/pricing/

Scaling

Fargate: To scale down for savings, we need to scale down the desired task count in the services, since we are charged for the utilization per task.

This can be done by selecting the resource and then selecting the Settings Tab. Enter a new value and then click the Save Changes button.


EC2 Launch Model: We can scale down the number of instances in the ASG, similar to what we do for existing ASGs.


Sample Data

AWS Describe clusters response.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 { "clusters": [ { "clusterArn": "arn:aws:ecs:us-east-2:078013660993:cluster/DevTestECS", "clusterName": "DevTestECS", "status": "ACTIVE", "registeredContainerInstancesCount": 2, "runningTasksCount": 0, "pendingTasksCount": 1, "activeServicesCount": 2, "statistics": [], "tags": [], "settings": [ { "name": "containerInsights", "value": "disabled" } ], "capacityProviders": [], "defaultCapacityProviderStrategy": [] } ], "failures": [] }

ECS Container Instances

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 { "containerInstances": [ { "containerInstanceArn": "arn:aws:ecs:us-east-2:078013660993: container-instance/DevTestECS/2da73aa37e964dcf979a757ce281785f", "ec2InstanceId": "i-0edae37d15d5c779c", "version": 3835, "versionInfo": { "agentVersion": "1.50.2", "agentHash": "5be7aa08", "dockerVersion": "DockerVersion: 19.03.13-ce" }, "remainingResources": [ { "name": "CPU", "type": "INTEGER", "doubleValue": 0.0, "longValue": 0, "integerValue": 2048 }, { "name": "MEMORY", "type": "INTEGER", "doubleValue": 0.0, "longValue": 0, "integerValue": 461 }, { "name": "PORTS", "type": "STRINGSET", "doubleValue": 0.0, "longValue": 0, "integerValue": 0, "stringSetValue": [ "22", "2376", "2375", "51678", "51679" ] }, { "name": "PORTS_UDP", "type": "STRINGSET", "doubleValue": 0.0, "longValue": 0, "integerValue": 0, "stringSetValue": [] } ], "registeredResources": [ { "name": "CPU", "type": "INTEGER", "doubleValue": 0.0, "longValue": 0, "integerValue": 2048 }, { "name": "MEMORY", "type": "INTEGER", "doubleValue": 0.0, "longValue": 0, "integerValue": 461 }, { "name": "PORTS", "type": "STRINGSET", "doubleValue": 0.0, "longValue": 0, "integerValue": 0, "stringSetValue": [ "22", "2376", "2375", "51678", "51679" ] }, { "name": "PORTS_UDP", "type": "STRINGSET", "doubleValue": 0.0, "longValue": 0, "integerValue": 0, "stringSetValue": [] } ], "status": "ACTIVE", "agentConnected": true, "runningTasksCount": 0, "pendingTasksCount": 0, "attributes": [ { "name": "ecs.capability.secrets.asm.environmentvariables" }, { "name": "ecs.capability.branch-cni-plugin-version", "value": "a21d3a41-" }, { "name": "ecs.ami-id", "value": "ami-02ef98ccecbf47e86" }, { "name": "ecs.capability.secrets.asm.bootstrap.logdriver" }, { "name": "ecs.capability.task-eia.optimized-cpu" }, { "name": "com.amazonaws.ecs.capability.logging-driver.none" }, { "name": "ecs.capability.ecr-endpoint" }, { "name": "ecs.capability.docker-plugin.local" }, { "name": "ecs.capability.task-cpu-mem-limit" }, { "name": "ecs.capability.secrets.ssm.bootstrap.logdriver" }, { "name": "ecs.capability.efsAuth" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.30" }, { "name": "ecs.capability.full-sync" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.31" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.32" }, { "name": "com.amazonaws.ecs.capability.logging-driver.fluentd" }, { "name": "ecs.capability.firelens.options.config.file" }, { "name": "ecs.availability-zone", "value": "us-east-2a" }, { "name": "ecs.capability.aws-appmesh" }, { "name": "com.amazonaws.ecs.capability.logging-driver.awslogs" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.24" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.25" }, { "name": "ecs.capability.task-eni-trunking" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.26" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.27" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.28" }, { "name": "com.amazonaws.ecs.capability.privilegedcontainer" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.29" }, { "name": "ecs.cpu-architecture", "value": "x86_64" }, { "name": "com.amazonaws.ecs.capability.ecr-auth" }, { "name": "ecs.capability.firelens.fluentbit" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.20" }, { "name": "ecs.os-type", "value": "linux" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.21" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.22" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.23" }, { "name": "ecs.capability.private-registryauthentication.secretsmanager" }, { "name": "ecs.capability.task-eia" }, { "name": "com.amazonaws.ecs.capability.logging-driver.syslog" }, { "name": "com.amazonaws.ecs.capability.logging-driver.awsfirelens" }, { "name": "ecs.capability.firelens.options.config.s3" }, { "name": "com.amazonaws.ecs.capability.logging-driver.json-file" }, { "name": "ecs.capability.execution-role-awslogs" }, { "name": "ecs.vpc-id", "value": "vpc-0c0aa8bb015165a05" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.17" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.18" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.19" }, { "name": "ecs.capability.docker-plugin.amazon-ecsvolume-plugin" }, { "name": "ecs.capability.task-eni" }, { "name": "ecs.capability.firelens.fluentd" }, { "name": "ecs.capability.efs" }, { "name": "ecs.capability.execution-role-ecr-pull" }, { "name": "ecs.capability.task-eni.ipv6" }, { "name": "ecs.capability.container-health-check" }, { "name": "ecs.capability.execute-command" }, { "name": "ecs.subnet-id", "value": "subnet-01274bff012ba6299" }, { "name": "ecs.instance-type", "value": "t3a.nano" }, { "name": "com.amazonaws.ecs.capability.task-iam-rolenetwork-host" }, { "name": "ecs.capability.container-ordering" }, { "name": "ecs.capability.cni-plugin-version", "value": "55b2ae77-2020.09.0" }, { "name": "ecs.capability.env-files.s3" }, { "name": "ecs.capability.secrets.ssm.environmentvariables" }, { "name": "ecs.capability.pid-ipc-namespace-sharing" }, { "name": "com.amazonaws.ecs.capability.task-iam-role" } ], "registeredAt": "2021-06-08T10:20:33.455000+05:30", "attachments": [], "tags": [] } ], "failures": [] }

ECS Services (AWS, launch model: EC2)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 { "services": [ { "serviceArn": "arn:aws:ecs:us-east-2:078013660993:service/DevTestECS/test-aman", "serviceName": "test-aman", "clusterArn": "arn:aws:ecs:us-east-2:078013660993:cluster/DevTestECS", "loadBalancers": [], "serviceRegistries": [], "status": "ACTIVE", "desiredCount": 1, "runningCount": 0, "pendingCount": 0, "launchType": "EC2", "taskDefinition": "arn:aws:ecs:us-east-2:078013660993:taskdefinition/test-task:1", "deploymentConfiguration": { "maximumPercent": 200, "minimumHealthyPercent": 100 }, "deployments": [ { "id": "ecs-svc/3318500728319905175", "status": "PRIMARY", "taskDefinition": "arn:aws:ecs:us-east-2:078013660993:task-definition/test-task:1", "desiredCount": 1, "pendingCount": 0, "runningCount": 0, "createdAt": "2021-06-07T14:41:01.532000+05:30", "updatedAt": "2021-06-07T14:41:01.532000+05:30", "launchType": "EC2" } ], "events": [ { "id": "ebc2e017-6b45-4130-afd4-a8c71d779376", "createdAt": "2021-06-24T15:50:05.954000+05:30", "message": "(service test-aman) is unable to consistently start tasks successfully. For more information, see the Troubleshooting section of the Amazon ECS Developer Guide." }], "createdAt": "2021-06-07T14:41:01.532000+05:30", "placementConstraints": [], "placementStrategy": [ { "type": "spread", "field": "attribute:ecs.availability-zone" }, { "type": "spread", "field": "instanceId" } ], "schedulingStrategy": "REPLICA", "createdBy": "arn:aws:iam::078013660993:user/aman.s@gopherslab.com", "enableECSManagedTags": true, "propagateTags": "NONE" } ], "failures": [] }

ECS Services (AWS, launch model: Fargate)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 { "services": [ { "serviceArn": "arn:aws:ecs:us-east-2:078013660993:service/DevTestECS/test-aman-fargate", "serviceName": "test-aman-fargate", "clusterArn": "arn:aws:ecs:us-east-2:078013660993:cluster/DevTestECS", "loadBalancers": [], "serviceRegistries": [], "status": "ACTIVE", "desiredCount": 1, "runningCount": 0, "pendingCount": 0, "launchType": "FARGATE", "platformVersion": "LATEST", "taskDefinition": "arn:aws:ecs:us-east-2:078013660993:taskdefinition/test-fargate-task:1", "deploymentConfiguration": { "maximumPercent": 200, "minimumHealthyPercent": 100 }, "deployments": [ { "id": "ecs-svc/6469025416466228103", "status": "PRIMARY", "taskDefinition": "arn:aws:ecs:us-east-2:078013660993:task-definition/test-fargate-task:1", "desiredCount": 1, "pendingCount": 0, "runningCount": 0, "createdAt": "2021-06-07T14:43:25.388000+05:30", "updatedAt": "2021-06-07T14:43:25.388000+05:30", "launchType": "FARGATE", "platformVersion": "1.4.0", "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-01274bff012ba6299" ], "securityGroups": [ "sg-0d38fd69eaa76adf1" ], "assignPublicIp": "ENABLED" } } } ], "roleArn": "arn:aws:iam::078013660993:role/aws-service-role/ecs.amazonaws.com/AWSServiceRoleForECS", "events": [{ "id": "224c8171-429f-409a-a5fd-e1410f0a1dfd", "createdAt": "2021-06-24T15:51:22.151000+05:30", "message": "(service test-aman-fargate) is unable to consistently start tasks successfully. For more information, see the Troubleshooting section of the Amazon ECS Developer Guide." }], "createdAt": "2021-06-07T14:43:25.388000+05:30", "placementConstraints": [], "placementStrategy": [], "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-01274bff012ba6299" ], "securityGroups": [ "sg-0d38fd69eaa76adf1" ], "assignPublicIp": "ENABLED" } }, "schedulingStrategy": "REPLICA", "createdBy": "arn:aws:iam::078013660993:user/aman.s@gopherslab.com", "enableECSManagedTags": true, "propagateTags": "NONE" } ], "failures": [] }

ECS Tasks (AWS)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 { "tasks": [{ "attachments": [{ "id": "04f9f338-cf11-4929-9436-aa2390c22172", "type": "ElasticNetworkInterface", "status": "ATTACHED", "details": [{ "name": "subnetId", "value": "subnet-0a9d15ed50082df61" }, { "name": "networkInterfaceId", "value": "eni-0c2c48b53cc7c6f7e" }, { "name": "macAddress", "value": "06:bf:71:6f:0b:9e" }, { "name": "privateIPv4Address", "value": "10.0.0.169" } ] }], "availabilityZone": "us-west-2a", "clusterArn": "arn:aws:ecs:us-west-2:078013660993:cluster/tutorial", "connectivity": "CONNECTED", "connectivityAt": "2020-04-22T12:17:03.464000-04:00", "containers": [{ "containerArn": "arn:aws:ecs:us-west-2:078013660993:container/2def8853-6717-48ab-bc44-a7c7480c4a06", "taskArn": "arn:aws:ecs:us-west-2:078013660993:task/0f339265-9dea-45e4-a827-8251bbfba98d", "name": "web", "image": "amazon/amazon-ecs-sample", "runtimeId": "229fc708a0025c40bc99f255bdace585778e6f67df8068c56d46dab2e90816d2", "lastStatus": "RUNNING", "networkBindings": [], "networkInterfaces": [{ "attachmentId": "04f9f338-cf11-4929-9436-aa2390c22172", "privateIpv4Address": "10.0.0.169" }], "healthStatus": "UNKNOWN", "cpu": "0" }], "cpu": "256", "createdAt": "2020-04-22T12:16:58.871000-04:00", "desiredStatus": "RUNNING", "group": "service:tutorial", "healthStatus": "UNKNOWN", "lastStatus": "RUNNING", "launchType": "FARGATE", "memory": "512", "overrides": { "containerOverrides": [{ "name": "web" }], "inferenceAcceleratorOverrides": [] }, "platformVersion": "1.3.0", "pullStartedAt": "2020-04-22T12:17:20.173000-04:00", "pullStoppedAt": "2020-04-22T12:17:22.173000-04:00", "startedAt": "2020-04-22T12:17:24.173000-04:00", "startedBy": "ecs-svc/1386207576422626542", "tags": [], "taskArn": "arn:aws:ecs:us-west-2:078013660993:task/0f339265-9dea-45e4-a827-8251bbfba98d", "taskDefinitionArn": "arn:aws:ecs:us-west-2:078013660993:taskdefinition/tutorial:1", "version": 3 }], "failures": [] }