Skip to content

Last version of AWS ECS Optimized AMI becomes unreachable

0

Hello there, I implemented a CloudFormation Stack for an ecs service using CDK. All worked great until last updates of the ECS Optimized AMI that is managed by CDK itself (it refers to a SSM Parameter store with the id of the AMI to use as default).

Task Definition is the same, the ecr image is the same, the ec2 instance type is the same but the ECS agent (v 1.106.x) when the instance is added to the ECS Cluster infrastructure disconnects even before it gets a task running on there. Trying to access the instance via SSM Session Manager is also unsuccessful because the Session Manager is not connected (before you ask, yes the instance is reachable via Session Manager when everything works).

I tried to upgrade the instance type, from t4g.nano to t4g.micro. Doing so it works ok but randomly also the micro gets unreachable. The task definition use "cpu": 1000 and "memoryReservation": 350. But as I said, also che t4g.micro sometimes gets unreachable so I don't know if this is related to the memory usage or what.

Do you have any clue on why this is happening or suggestions?

Thank you. S.

1 Answer
0

When an ECS-optimized AMI instance becomes unreachable and the ECS agent disconnects before tasks can run, there are several potential causes to investigate. First, check the instance's system logs through the EC2 console by selecting your instance, then choosing Actions > Monitor and troubleshoot > Get system log. This can reveal kernel problems, service configuration issues, or boot failures that might explain why the instance becomes unreachable. You can also capture a screenshot of the instance to see its current state, which is particularly useful for diagnosing boot-related issues. Monitor the CPUUtilization metric in CloudWatch to verify whether the operating system is actually active and responsive. If the instance appears stuck during boot or becomes unresponsive, try rebooting it first. If rebooting doesn't resolve the issue, you may need to recover the instance by stopping and starting it, which can help if there's an underlying host issue. Regarding your resource configuration, with a task using 1000 CPU units and 350 MB memory reservation on t4g.nano instances (which have limited resources), you might be experiencing resource exhaustion. The t4g.nano has only 512 MB of memory, and after accounting for the operating system and ECS agent overhead, there may not be sufficient resources for your task. Even on t4g.micro instances with 1 GB of memory, if multiple tasks are scheduled or if there are memory spikes, the instance could become unresponsive. Consider using larger instance types with more headroom, or adjust your task's CPU and memory requirements. Also verify that your security groups, VPC configuration, and IAM instance profile are correctly configured to allow the ECS agent to communicate with the ECS service and for Systems Manager to function properly. If the issue persists across AMI versions, you might want to temporarily pin to a known working AMI version while investigating further.
Sources
Troubleshoot an unreachable Amazon EC2 instance - Amazon Elastic Compute Cloud
Common screenshots to troubleshoot unreachable Windows instances - Amazon Elastic Compute Cloud

answered 2 months ago

AWS
SUPPORT ENGINEER

reviewed 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.