1
votes

I'm aware that there are similar question posted here, but none of them address this specific issue.

How to create an ECS cluster via CLI tools, aws-cli and/or ecs-cli, with using your own custom AMI stored in EC2 as an AMI image?

Is this even possible currently or do I need to turn to CloudFormation?

EDIT: I had a major confusion about the service architecture of ECS in terms of distributing containers on container instances (EC2 instances registered to the cluster).

So the container instance runs on an AMI. Which can be a custom built AMI, but such would needed only in some special circumstances. It's recommended to use an ECS-optimized Amazon Linux AMI by as maintained by AWS and is updated about once a month.

Another confusion point was with Docker Compose approach and the ECS CLI tool. Some experts think that while the ECS CLI is released and maintained by AWS, and being already 3 years old at this point in 2019, it is not suitable for production usage. So am using AWS CLI instead, and dealing with clusters, task definitions, and (task scheduling) services directly.

1

1 Answers

1
votes

I would rather run the custom stuff within the container defined by dockerfile on ECS optimized AMI

But to run custom AMI

1) Pre-requisite is to have AMI image with ECS Agent installed

2) Then I would try ecs-cli up command with defined --image-id

 ecs-cli up
      --keypair <my-keypair>
      --launch-type EC2
      --size 2
      --instance-type t2.micro
      --instance-role ECSMediumRole
      --vpc <my-vpc>
      --image-id ami-XXXXXXXX # Custom Image ID with ECS Agent installed
      --cluster-config <my-cluster-config>
      --ecs-profile <my-ecs-profile>
      --security-group <my-security-group-id>
      --region us-east-1
      --subnets <my-public-vpc-subnet>