-
Install Docker/Create basic docker file for the application.
-
An IAM role needed to be in place to use ECS, details on it's creation are here.
This role is created automatically during the ecs first run wizard, provided the user has IAM permissions to create said role.
The new role should be available to view here -
Create {application name} docker repo from the ecs repositories page
-
Install AWS CLI locally to enable the ability to push to the new docker repo. Instructions here
-
Retrieve the docker login command that can be used to authenticate the Docker client to the new registry
aws ecr get-login --region {aws region ie. us-east-1}
-
On the docker client, run the docker login command that was returned in the previous step.
-
Build the docker image from the dockerfile created in step one.
docker build -t {application name} .
- Tag the image so that it can be pushed to the repository
docker tag {application name}:latest {repository-url/image}:latest
- Push this image to the AWS repository
docker push {repository-url/image}:latest
-
Create a cluster for the application from the clusters page
-
Create a task defenition for the application's container from the task definitions page Be sure to set the image as the url pushed to in step 9, add any required container configuration in the advanced settings.
-
Create a new "Amazon ECS-Optimized Amazon Linux AMI" EC2 instance for the container to run on.
The following will need to be configured on this instance:
-
Set the IAM role as ecsInstanceRole
-
In advanced details, set the User Data as
#!/bin/bash echo ECS_CLUSTER={cluster_name_from_step_10} >> /etc/ecs/ecs.config
-
Create a Service for the contianer to run in on the cluster created from step 10, setting the task definition as appropriate https://console.aws.amazon.com/ecs/home#/clusters/{cluster_name_from_step_10}/services
- Create a EC2 Load Balancer for each application to be deployed. The port that users of the application will hit externally will need to be mapped to the port on each EC2 instance where the application will be hosted. The port that the EC2 instance will be listening on will need to be exposed in the instance's security group.
See: http://docs.aws.amazon.com/AmazonECS/latest/developerguide/images/load-balancing.png
Take care to ensure that the load balancer is created within the correct VPC.
- Create an EC2 launch configuration "Amazon ECS-Optimized Amazon Linux AMI" for the containers to run on.
The following will need to be configured on this instance:
-
Set the IAM role as ecsInstanceRole
-
In advanced details, set the User Data as
#!/bin/bash echo ECS_CLUSTER={cluster_name_from_step_10} >> /etc/ecs/ecs.config
-
Create an auto scaling group using the newly created launch configuration and load balancer.