aws-samples / aws-cdk-examples

Example projects using the AWS CDK
Apache License 2.0
5.09k stars 2.14k forks source link

Python ECS Example does not register EC2 instances with the ECS Cluster #562

Open ajbeach2 opened 2 years ago

ajbeach2 commented 2 years ago

What is the problem?

https://github.com/aws-samples/aws-cdk-examples/blob/master/python/ecs/ecs-service-with-advanced-alb-config/app.py

The Python ECS example does not work as expected. The ECS cluster is created and the auto scaling groups are created, but no ec2 instances are registered.

Additionally, the STANDARD5 (m5.micro) are not available in us-east-1.

Reproduction Steps

Run the python example in us-east-1 https://github.com/aws-samples/aws-cdk-examples/blob/master/python/ecs/ecs-service-with-advanced-alb-config/app.py

  1. Observe that m5.micro are not available in us-east-1
  2. Change STANDARD5 to BUSTRABLE (or t2.micro)
  3. cdk deploy
  4. Observer that AWS::ECS::Service CREATE_IN_PROGRESS in cloudformation and this never changes.
  5. Observe the no ec2 instances are registered to the ECS cluster in the aws console

What did you expect to happen?

I expected an ECS cluster with ec2 instances assigned and the example to work as written.

What actually happened?

ECS cluster gets created, ec2 instances get created, but these instances are not registered to the ECS Cluster.

CDK CLI Version

1.130.0 (build 9c094ae)

Framework Version

No response

Node.js Version

v16.13.0

OS

Ubuntu

Language

Python

Language Version

3.8.2

Other information

No response

ajbeach2 commented 2 years ago

I was able to resolve the issue.

I am using an existing vpc with a modified version of this example. The issue was that the autoscaling group was launching in private instances. By using public subnets, and and associating a public ip, the ecs agent was able to register to the cluster.