Search code examples
amazon-web-servicesdockeramazon-ec2amazon-ecs

How to run codedeploy agent installation script in AWS ECS?


I have an AWS ECS cluster defined with a service that uses Replica service type. It creates an EC2 isntance with a docker container. I can access it through browser and all this stuff...

The issue is that I have to connect through ssh to the EC2 instance and run:

sudo yum update -y
sudo yum install-y ruby
sudo yum install-y wget
cd /home/ec2-user
wget https://aws-codedeploy-eu-west-1.s3.eu-west-1.amazonaws.com/latest/install
chmod +x ./install
sudo ./install auto

It install codedeploy agent, so I can connect github to the instance and CI/CD code. I would like to set up this automatically in every server that the ECS definition creates. For example if i stop the EC2 instance, the cluster raises a new EC2 instance, which doesn't have this agent...

I saw that I should configure your Amazon ECS container instance with user data, but first of all is that I am not able to find this option, and I am not quite sure if it runs into the EC2 isntance or in the docker itself.


Solution

  • Based on the comments.

    The solution was to use Launch Template or Launch Configurations.