Skip to content

Instantly share code, notes, and snippets.

@techjacker
Created November 18, 2015 17:46
Show Gist options
  • Save techjacker/d12b9f98f466f934f96f to your computer and use it in GitHub Desktop.
Save techjacker/d12b9f98f466f934f96f to your computer and use it in GitHub Desktop.
Instructions for deploying an ec2 instance based on a docker file using AWS EC2 Container Service using the AWS CLI tool

aws ecs help

echo $AWS_DEFAULT_PROFILE aws configure --profile andrew aws ec2 describe-instance-status --profile andrew --instance-ids i-81c24938

  1. create VPC

Create Amazon ECS Container Instance IAM Role

docs

  1. Create Role
ecsInstanceRole
Role ARN
arn:aws:iam::920351411162:role/ecsInstanceRole
Instance Profile ARN(s)
arn:aws:iam::920351411162:instance-profile/ecsInstanceRole
Path
/
Creation Time
2015-10-06 12:59 UTC+0100

AmazonS3ReadOnlyAccess
AmazonEC2ContainerServiceforEC2Role

Launch ec2 Instance with ecsInstanceRole

docs

with AWS cli

  1. choose the Amazon ECS-optimized AMI eu-west-1 amzn-ami-2015.09.a-amazon-ecs-optimized ami-6b12271c

Configure ec2 Instance with env vars (ie store an ecs.config file in Amazon S3)

docs

  1. create private s3 bucket docs

Bucket: ago.containers Region: Ireland Creation Date: Tue Oct 06 15:35:11 GMT+100 2015 Owner: mail

make bucket

aws s3 mb s3://ago.containers

remove bucket

aws s3 rb s3://ago.containers
  1. Create an ecs.config
cat ~/.dockercfg > ecs.config
  1. Upload the ecs.config file to your Amazon S3 bucket docs
aws s3 cp ecs.config s3://ago.containers/gomailer.ecs.config \
  --grants read=id=e4a490498ca3b7dc3e0812b46ca312c313d332da47bf03f87c53c29ef5f48f89

list buckets and contents

aws s3 ls
aws s3 ls s3://ago.containers
  1. launch ecs instance

choose the Advanced Details list paste the following script into the User data field

#!/bin/bash
#export ECS_CLUSTER=your_cluster_name
export AWS_DEFAULT_REGION=eu-west-1
yum install -y aws-cli
aws s3 cp s3://ago.containers/gomailer.ecs.config /etc/ecs/ecs.config
  • add more env vars if you want docs

Create Amazon ECS Service Scheduler IAM Role

docs

  1. Create Role
ecsServiceRole
Role ARN
arn:aws:iam::920351411162:role/ecsServiceRole
Instance Profile ARN(s)
arn:aws:iam::920351411162:instance-profile/ecsServiceRole
Path
/
Creation Time
2015-10-06 15:02 UTC+0100

AmazonEC2ContainerServiceRole

create role CLI

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html?console_help=true

=================================================================================================

Step 1: Create a Cluster

aws ecs create-cluster --cluster-name MyCluster

=================================================================================================

Step 2: Launch an Instance with the Amazon ECS AMI

(with the AWS gui)

=================================================================================================

Step 3: Get DNS + IP from instance

aws ec2 describe-instances --instance-ids i-81c24938 aws ec2 describe-instance-status --instance-ids i-81c24938

=================================================================================================

Step 4: Check Instances associated with cluster

aws ecs list-container-instances --cluster default aws ecs describe-container-instances --cluster default --container-instances 44442be0-f239-4062-b6d1-66567908a51e

=================================================================================================

Step 5: De-/Register a task definition

aws ecs register-task-definition --cli-input-json file://$(AWS_TASK_DEFINITION_FILE) aws ecs describe-task-definition --task-definition gomailer:6 aws ecs deregister-task-definition --task-definition gomailer:6

aws ecs list-task-definitions

=================================================================================================

Step 6: Run/Stop a task

aws ecs run-task --cluster default --task-definition gomailer:6 --count 1 aws ecs run-task --cluster default --task 61f30b78-2f5f-4dcf-b560-09ee330be9b4

aws ecs list-tasks --cluster default

aws ecs stop-task --cluster default --task 61f30b78-2f5f-4dcf-b560-09ee330be9b4 aws ecs describe-tasks --cluster default --task 61f30b78-2f5f-4dcf-b560-09ee330be9b4

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