AWS ECS Error when running task: No Container Instances were found in your cluster

后端 未结 10 1599
时光说笑
时光说笑 2020-11-28 04:02

Im trying to deploy a docker container image to AWS using ECS, but the EC2 instance is not being created. I have scoured the internet

相关标签:
10条回答
  • 2020-11-28 04:16

    Currently, the Amazon AWS web interface can automatically create instances with the correct AMI and the correct name so it'll register to the correct cluster.

    Even though all instances were created by Amazon with the correct settings, my instances wouldn't register. On the Amazon AWS forums I found a clue. It turns out that your clusters need internet access and if your private VPC does not have an internet gateway, the clusters won't be able to connect.

    The fix

    In the VPC dashboard you should create a new Internet Gateway and connect it to the VPC used by the cluster. Once attached you must update (or create) the route table for the VPC and add as last line

    0.0.0.0/0 igw-24b16740  
    

    Where igw-24b16740 is the name of your freshly created internet gateway.

    0 讨论(0)
  • 2020-11-28 04:20

    I figured this out after a few more hours of investigating. Amazon, if you are listening, you should state this somewhere in your management console when creating a cluster or adding instances to the cluster:

    "Before you can add ECS instances to a cluster you must first go to the EC2 Management Console and create ecs-optimized instances with an IAM role that has the AmazonEC2ContainerServiceforEC2Role policy attached"

    Here is the rigmarole:

    1. Go to your EC2 Dashboard, and click the Launch Instance button.

    2. Under Community AMIs, Search for ecs-optimized, and select the one that best fits your project needs. Any will work. Click next.

    3. When you get to Configure Instance Details, click on the create new IAM role link and create a new role called ecsInstanceRole.

    4. Attach the AmazonEC2ContainerServiceforEC2Role policy to that role.

    5. Then, finish configuring your ECS Instance.
    NOTE: If you are creating a web server you will want to create a securityGroup to allow access to port 80.

    After a few minutes, when the instance is initialized and running you can refresh the ECS Instances tab you are trying to add instances too.

    0 讨论(0)
  • 2020-11-28 04:20

    If you have come across this issue after creating the cluster

    Go the ECS instance in the EC2 instances list and check the IAM role that you have assigned to the instance. You can identify the instances easily with the instance name starts with ECS Instance

    After that click on the IAM role and it will direct you to the IAM console. Select the AmazonEC2ContainerServiceforEC2Role policy from the permission policy list and save the role.

    Your instances will be available in the cluster shortly after you save it.

    0 讨论(0)
  • 2020-11-28 04:21

    When this happens, you need to look to the following:

    1. Your EC2 instances should have a role with AmazonEC2ContainerServiceforEC2Role managed policy attached to it
    2. Your EC2 Instances should be running AMI image which is ecs-optimized (you can check this in EC2 dashboard)
    3. Your VPC's private subnets don't have public IPs assigned, OR you do not have an interface VPC endpoint configured, OR you don't have NAT gateway set up

    Most of the time, this issue appears because of the misconfigured VPC. According to the Documentation:

    QUOTE: If you do not have an interface VPC endpoint configured and your container instances do not have public IP addresses, then they must use network address translation (NAT) to provide this access.

    • To create a VPC endpoint: Follow to the documentation here
    • To create a NAT gateway: Follow to the documentation here

    These are the reasons why you don't see the EC2 instances listed in the ECS dashboard.

    0 讨论(0)
  • 2020-11-28 04:22

    Other suggested checks

    1. Selecting the suggested AMI which was specified for the given region solved my problem.

      To find out the AMI - check Launching an Amazon ECS Container Instance.

    2. By default all the ec2 instances are added to default cluster . So the name of the cluster also matters.

    See point 10 at Launching an Amazon ECS Container Instance.

    More information available in this thread.

    0 讨论(0)
  • 2020-11-28 04:22

    Another possible cause that I ran into was updating my ECS cluster AMI to an "Amazon Linux 2" AMI instead of an "Amazon Linux AMI", which caused my EC2 user_data launch script to not work.

    0 讨论(0)
提交回复
热议问题