0

How would I have the AWS EC2 Container Service grab a docker image from a private repo on Docker Hub using CloudFormation (assuming that is the cause of the error below)?

I keep on getting this error:

... was unable to place a task because no container instance met all of its requirements. Reason: No Container Instances were found in your cluster. 

I've added an ecs.config file to S3 with these contents:

ECS_ENGINE_AUTH_TYPE=dockercfg
ECS_ENGINE_AUTH_DATA={"https://index.docker.io/v1/":{"auth":"MY_AUTH_TOKEN"=,"email":"MY_EMAIL"}}

And these are relevant excerpts from my CloudFormation stack.yml file, please forgive my indenting, some of it may be off:

 AutoScalingLaunchConfiguration:
    Type: "AWS::AutoScaling::LaunchConfiguration"
    Properties:
      ImageId: ami-241bd844
      InstanceType: t2.micro
      KeyName: { "Ref": "KeyPair" }
      IamInstanceProfile: { "Ref": "EC2InstanceProfile" }
      SecurityGroups:
        - { "Ref": "EC2InstanceSecurityGroup" }
      UserData: {
        "Fn::Base64": { "Fn::Join": ["", [
          "#!/bin/bash\n",
          "echo <ECS_CLUSTE>,l</ECS_CLUSTE>R=", { "Ref" : "EcsCluster" }, " >> /etc/ecs/ecs.config\n",
          "yum install -y aws-cli\n",
          "aws s3 cp s3://MY_BUCKET/ecs.config /etc/ecs/ecs.config"
    ] ] }
  }
AppTaskDefinition: 
    Type: "AWS::ECS::TaskDefinition"
    Properties:
      ContainerDefinitions:
        - Name: app
          Image: organization/privateapp
          Memory: 450
          Environment:
            - Name: DB_HOST
              Value: { "Ref": "DbHost" }
            - Name: DB_USER
              Value: { "Ref": "DbUsername" }
            - Name: DB_PASSWORD
              Value: { "Ref": "DbPassword" }
          MountPoints:
            - ContainerPath: /var/www/app
              SourceVolume: webroot
 Volumes: 
        - Name: webroot
          Host: 
            SourcePath: /ecs/webroot
EC2InstanceProfile:
    Type: "AWS::IAM::InstanceProfile"
    Properties: 
      Path: "/"
      Roles: [ { "Ref": "EC2InstanceRole" } ]
  EC2InstanceRole:
    Type: "AWS::IAM::Role"
    Properties:
      AssumeRolePolicyDocument: {
         "Version": "2012-10-17",
         "Statement": [
          {
            "Effect": "Allow",
            "Principal": { "Service": [ "ec2.amazonaws.com" ] },
            "Action": [ "sts:AssumeRole"]
          }
        ]
      }
       Policies: [ 
         {
            "PolicyName": "giveaccesstos3",
            "PolicyDocument": {
            "Version": "2012-10-17",
            "Statement": [ {
              "Action": ["s3:GetObject"],
              "Sid": "Stmt0123456789",
              "Resource": ["arn:aws:s3:::MY_BUCKET/ecs.config"],
              "Effect": "Allow"
            }]
          }
      }]
      Path: "/"
      ManagedPolicyArns: 
    - "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role" 
Justin
  • 2,224
  • 2
  • 22
  • 28
  • 1
    You echo the ECS cluster name into /etc/ecs/ecs.config, and then you replace the file with what you have on S3, I am sure, if you get inside tthe instance and check your ecs config, you will not be seeing the correct cluster name.. And because of this, your cluster doesn't register any instances. – Shibashis Aug 12 '16 at 15:10
  • 1
    Yeah, I got this all working now shortly after I made the question! I realized on how stupid I am and never followed-up with this question. Thanks though for looking at it! Appreciate it. – Justin Aug 12 '16 at 16:28
  • Possible duplicate of [AWS ECS Error when running task: No Container Instances were found in your cluster](https://stackoverflow.com/questions/36523282/aws-ecs-error-when-running-task-no-container-instances-were-found-in-your-clust) – kenorb Mar 28 '19 at 01:04

0 Answers0