Before you can add ECS instances to a cluster you must first go to the EC2 Management Console and create ecs-optimized instances with an IAM role that has the AmazonEC2ContainerServiceforEC2Role policy attached.
Launch Instance button.Community AMIs, search for ecs-optimized, and select the one that best fits your project needs. Any will work. Click next.Configure Instance Details, click on the create new IAM role link and create a new role called ecsInstanceRole.AmazonEC2ContainerServiceforEC2Role policy to that role.default cluster. If you want to launch into your own cluster instead of the default, choose the Advanced Details list and paste the following script into the User data field, replacing your_cluster_name with the name of your cluster.#!/bin/bash
echo ECS_CLUSTER=your_cluster_name >> /etc/ecs/ecs.config
NOTE: If you a creating a web server you will want to create a securityGroup to allow access to port 80.
aws ecr create-repository --repository-name example-repositoryaws ecr get-login --region us-east-1 | shdocker build -t example-image .docker tag example-image:latest example-namespace/example-image:latestdocker push example-namespace/example-image:latestaws ecs register-task-definition --cli-input-json example-task.jsonaws ecs run-task --task-definition example-task