Search code examples
amazon-web-servicesdockeramazon-ec2amazon-ecsaws-cdk

How can I calculate the appropriate spec for container and EC2?


I am using ECS on EC2.

I met this problem when deployng.

service `myapp-dev-service` was unable to place a task because no container instance met all of its requirements. The closest matching container-instance f246f9a525a542229c060c62a9529314 is missing an attribute required by your task. For more information, see the Troubleshooting section of the Amazon ECS Developer Guide.

My instance is t2.small

And I have one taskdefinition which has two containers.

const djangoContainer = taskDefinition.addContainer('adminContainer', {
  image: djangoImage,
  containerName:`myapp-django-container`,
  memoryLimitMiB: 256,
})
const nginxContainer = taskDefinition.addContainer('nginxContainer', {
  image: nginxImage,
  containerName:`myapp-nginx-container`,
  memoryLimitMiB: 256,
})

So I guess memory of t2.small(2GB) is enough for this task definition.

Why this happen? and how can I calculate and decide the nodes size??


Solution

  • You have problem with memory limits. In Amazon ECS, memory can be defined at both the task level and at each container level. If you specify a hard limit (memory), your container will be killed if it attempts to exceed that limit. If you specify a soft limit (memoryReservation), ECS reserves that amount of memory for your container; however, the container can request up to the hard limit (if specified) or all of the available memory on the container instance, whichever is reached first. If you specify both, the hard limit must be greater than the soft limit. Read more allocate ECS limits