Launch EC2 instance for ECS cluster

Launch EC2 instance for ECS cluster

EC2 part

  • go to EC2 dashboard

  • click *create instance

  • step 1. Choose AMI

  • step 2. Choose Instance Type -> pass

  • step 3. Configure Instance -> you must set User data

    • in Advance Details section put User data 'As text'

# you must put this in User data 'As text'

#!/bin/bash
echo "ECS_CLUSTER=${CLUSTER_NAME}" >> /etc/ecs/ecs.config


e.g 

#!/bin/bash
echo "ECS_CLUSTER=some-clust-name" >> /etc/ecs/ecs.config
  • step 4. Add Storage -> pass

  • step 5. Add Tags -> pass

  • step 6. Configure Security Group -> select your VPC default or create new one

  • step 7. review and launch -> pass

Don't forget attach *ecsInstanceRole

How can I execute user data to automatically create a file with every restart of my Amazon EC2 instance?

Short Description

By default, user data scripts and cloud-init directives run only during the first boot cycle when an instance is launched.

if instance failed to register on ECS you should make 'ecs.config' maunally ( NOT RECOMMEND)

$ ssh -i ${PEM_KEY_NAME}.pem ec2-user@${EC2-DNS}
$ cd /ect/ecs
$ sudo touch ecs.config
$ sudo vi ecs.config

sudo /usr/libexec/amazon-ecs-init start

Start the Docker daemon.

[ec2-user ~]$ sudo service docker start

You the see the agent logs in: /var/log/ecs

change instance type

instance settings > Change instance type

ECS part

  • select service

  • service update and check *Force new deployment

  • click update


free -m
cat /proc/cpuinfo

Amazon ECS-optimized AMIs

Bootstrapping Container Instances with Amazon EC2 User Data

Last updated

Was this helpful?