'Can we use custom AMI for the creation of ECS cluster?

I have created a custom AMI that has certain softwares and scripts preloaded in it.

  • Can I use this AMI for the ECS Cluster?
  • I do not see any option to add AMI while creating a cluster


Solution 1:[1]

Yes, you can. You need to ensure that the EC2 instances are running the ECS Agent.

To attach EC2 instances (using any AMI) to an ECS cluster, we just need to pass the corresponding cluster name to ECS_CLUSTER variable.

Reference: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-install.html

Solution 2:[2]

For your instance to be available on the cluster, you will have to create the default cluster.

if you have a custom ecs cluster, you can set the cluster name using the userdata section.

The ecs agent expects the cluster name inside the ecs.config file available at /etc/ecs/ecs.config.

You can set it up at instance boot up using userdata script

#!/bin/bash
echo ECS_CLUSTER={cluster_name} >> /etc/ecs/ecs.config

That instance shuld IAM role ecsinstance

Solution 3:[3]

Yes, you can . What you need to do is :

  1. Create a empty Cluster (There will be a checkbox for you to select)

  2. Create a Ec2 with the AMI of your choice but you need to ensure : a. you have the ecs-agent available on the Ec2 b. Add to the ecs.config file the key-value pair i.e ECS_CLUSTER=

Once it's done the container instance(ec2) will be visible on the ECS Cluster as 'container instances'

Solution 4:[4]

To anyone with these difficulties, create the role and the profile and attach it to the instance in the launch template of your autogroup as the previous answers comment.

However, for the part of the ECS_CLUSTER I was using an AMI not prepared for ECS, a Deep Learning AMI. This AMI didn't have neither YUM so I installed things with get-apt. In the launch template, add these lines to user data box:

#!/bin/bash
cd ~
curl -O https://s3.eu-west-1.amazonaws.com/amazon-ecs-agent-eu-west-1/amazon-ecs-init-latest.amd64.deb
sudo dpkg -i amazon-ecs-init-latest.amd64.deb
sudo mkdir /etc/ecs/
sudo echo ECS_CLUSTER=YOURCLUSTER >> /etc/ecs/ecs.config
sudo systemctl start ecs

Change YOURCLUSTER to your cluster name, and for the curl, select the one in your zone (Check Installing the Amazon ECS container agent on a non-Amazon Linux EC2 instance)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sai Prasad
Solution 2 Ashok Reddy
Solution 3 vijay
Solution 4 Learning from masters