Skip to content

Instantly share code, notes, and snippets.

@campezzi
Last active February 22, 2021 02:02
Show Gist options
  • Save campezzi/83656ed49d0948ba7b6dfd5a4b946d4b to your computer and use it in GitHub Desktop.
Save campezzi/83656ed49d0948ba7b6dfd5a4b946d4b to your computer and use it in GitHub Desktop.
Amazon ECS deployment using the ecs-cli
# Full documentation: http://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_CLI.html
# Replace the cluster name, keypair, exposed ports etc. as necessary.
# Install the ECS CLI and make it executable
sudo curl -o /usr/local/bin/ecs-cli https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest
sudo chmod +x /usr/local/bin/ecs-cli
# Configure the CLI (login details, region and cluster name)
ecs-cli configure --region ap-southeast-2 --access-key $AWS_ACCESS_KEY_ID --secret-key $AWS_SECRET_ACCESS_KEY --cluster CreateBTATaskUI
# Create the cluster (by default, spins a single t2.micro instance)
# This should be done manually once for each project
ecs-cli up --keypair service_stubs --capability-iam --port 5002
# Bring up the service
ecs-cli compose --file ecs-compose.yml service up
# Scale the service
ecs-cli compose --file ecs-compose.yml service scale 3
# Stop the service
ecs-cli compose --file ecs-compose.yml service stop
# Delete the service
ecs-cli compose --file ecs-compose.yml service rm
my_awesome_server:
image: ACCOUNT_ID_HERE.dkr.ecr.us-west-2.amazonaws.com/IMAGE_NAME:IMAGE_TAG
ports:
- "5002:80"
environment:
- SOME_ENVIRONMENT_VARIABLE=exposed_in_container
@campezzi
Copy link
Author

campezzi commented Jul 5, 2016

When starting a new project, configure the CLI for a new cluster named after it and run the create cluster command. This will take a few minutes as it spins up EC2 instance(s) that are pre-baked to run containers. Once that's done, you should be able to bring up the service.

Stopping/starting the service will cause the images used by the service to be re-downloaded (even if the tag hasn't changed).

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