- Newest
- Most votes
- Most comments
So from the code you can see I was using the default amazon linux image. It is not a custom image or special AMI.
.machineImage(MachineImage.latestAmazonLinux())
But that appears to NOT be compatible with ECS cluster requirements. The fix was simple:
.machineImage(EcsOptimizedImage.amazonLinux2())
Switching the EcsOptimizedImage object I can spin up an ECS image that matches the requirements. Once I deployed that I saw it register with the cluster and my image started up. There are plenty of other issues I have to fix. It's still not working, but at least it's registering with the cluster now.
Hello,
Warm Greetings from AWS Support.
I am Tejas from the AWS Support Team.
I have read your query and I understand that you have a CDK script which is trying to create an ECS Cluster , task and an application loadbalancer.
You have mentioned that is not registered with load balancer target group and the task never starts.
You are also suspecting that the EC2 instance does not gets registered with the cluster and the cdk scripts keeps waiting for it get healthy.
You have also asked the following queries as to which part is creating the ec2 instance and if the addCapacity is declaring the specification of the Ec2 instance and further follow up questions related to the instance being launched.
I have checked your cdk script and I would request you to check the following things mentioned below:-
=============================================
I would like to start by answering your query, The instance is being created in the cluster (). I noticed that the AMI used in the code is mentioned as " AMAZON_LINUX_2 ".
Answering your next query. Yes, The addcapacity call is the one which declares the specification of the instance.
I would request you to Check the AMI of your instance
If the AMI that you use for the EC2 instance is a copied or custom AMI, then confirm that the instance has the following components:
-
A modern Linux distribution running at least version 3.10 of the Linux kernel.
-
Latest version of the Amazon ECS Linux container agent.
-
A Docker daemon running at least version 1.9.0 and any Docker runtime dependencies (from the Docker website). To view the current
Docker version, run the command sudo docker version. For information about installing the latest Docker version on your particular Linux distribution, see Docker documentation for Install Docker engine on the Docker website.
[NOTE] The Amazon ECS optimized AMIs [+] https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html are preconfigured with these requirements. It's a best practice to use Amazon ECS optimized AMIs unless your application requires version that's not yet available in that AMI.
===============================================
I have read your script and compared your script with a script on github. I am pasting the link for the gitbhub script for your reference as well
[Note] On comparing the script , I have found that the load balancer is missing the listener in your script.
I have then followed the documentation for python as well [3] https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_ecs/README.html#clusters
Please check the section " Include an application/network load balancer " the below listener is missing from your code.
listener = lb.add_listener("Listener", port=80)
Please refer to documentation [3] for more details.
I would like to inform you that the Your Amazon EC2 instance can't register with or join an Amazon ECS cluster because of one or more of the following reasons:
The ECS endpoint can't access the Domain Name System (DNS) hostname of the instance publicly.
Your public subnet configurations are incorrect.
Your private subnet configurations are incorrect.
Your VPC endpoints are incorrectly configured.
Your security groups don't allow network traffic.
The EC2 instance doesn't have the required AWS Identity and Access Management (IAM) permissions. Or, the ecs:RegisterContainerInstance API call is denied.
The instance user data for your ECS container is incorrectly configured.
The ECS agent is stopped or not running on the instance.
The launch configuration of the Auto Scaling group isn't correct (if your instance is part of an Auto Scaling group).
The Amazon Machine Image (AMI) that you use for your instance doesn't meet the prerequisites.
Below is a detailed documentation which will provide details of the all the above points which are mentioned above.
IMP [+] https://repost.aws/knowledge-center/ecs-instance-unable-join-cluster
You can also debug more by checking the relevant api calls in cloudtrail where resources are present in your account.
I hope the above information helps. In case you feel I missed out to address something more to your concern, or if we can otherwise provide any additional assistance with regard to this matter, please do not hesitate to let me know, I’ll be more than happy to assist you.
Relevant content
- asked 6 days ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 5 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 4 months ago