Skip to content

Instantly share code, notes, and snippets.

@greglboxer
Last active February 24, 2016 20:41
Show Gist options
  • Save greglboxer/c268e135bf7d748c1217 to your computer and use it in GitHub Desktop.
Save greglboxer/c268e135bf7d748c1217 to your computer and use it in GitHub Desktop.
Rough outline of the steps taken to get a basic angular webapp up and running on the Amazon EC2 Container Service

Single Container on a Single EC2 Instance

  1. Install Docker/Create basic docker file for the application.

  2. 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

  3. Create {application name} docker repo from the ecs repositories page

  4. Install AWS CLI locally to enable the ability to push to the new docker repo. Instructions here

  5. 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}
  1. On the docker client, run the docker login command that was returned in the previous step.

  2. Build the docker image from the dockerfile created in step one.

docker build -t {application name} .
  1. Tag the image so that it can be pushed to the repository
docker tag {application name}:latest {repository-url/image}:latest
  1. Push this image to the AWS repository
docker push {repository-url/image}:latest
  1. Create a cluster for the application from the clusters page

  2. 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.

  3. 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:

  1. Set the IAM role as ecsInstanceRole

  2. In advanced details, set the User Data as

    #!/bin/bash
    echo ECS_CLUSTER={cluster_name_from_step_10} >> /etc/ecs/ecs.config
    
  3. 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

Load Balancing Containers Accross Multiple Autoscaled EC2 Instances

  1. 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.

  1. 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:

  1. Set the IAM role as ecsInstanceRole

  2. In advanced details, set the User Data as

    #!/bin/bash
    echo ECS_CLUSTER={cluster_name_from_step_10} >> /etc/ecs/ecs.config
    
  3. Create an auto scaling group using the newly created launch configuration and load balancer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment