I am trying to add EC2
to ECS
as container instance by using AutoScalingGroup
.
However, EC2
launched correctly but, it is not registered to ECS
.
I have checked the prividge
, however it corrects.
And no error in cloudtrail.
Then, I have tryed the same setting(EC2
,AutoScalingGroup
,ECS
) in another AWS, it woks, correctly registered as Container instance.
I suspect, the difference between these two AWS are subnet
or VPC
....
Both ECS and EC2 are on the same subnet,but
In AWS A(can not registered),the subnet using the virtual private gateway, In AWS B(registered correctly) the subnet using private subnet with Nat gateway.
I guess this difference might be relevant.
ANy help appreciated. thank you .
Without an Internet connection, the EC2 instance cannot connect to the AWS API, so it can't register with the ECS service. You mentioned ECS and EC2 are "in the same VPC" but that is not true, the AWS ECS service itself isn't actually in a VPC at all, you interact with it through the AWS API that is on the public Internet. You either need to give the EC2 instances access to the Internet, or create the necessary VPC endpoints to allow them access to the necessary AWS API resources.
You will need to create VPC endpoints for the ECS Service, S3 and ECR, and possibly some other AWS services like Secrets Manager, depending on what you are doing.