Coder Social home page Coder Social logo

ecs-spot-demo's Introduction

ECS Spot Fleet Demo

This is a sample template that demonstrates how to use ECS with Spot Fleets.

Usage

  1. Launch Stack with Spot Fleets
  2. Deploy Demo App
  3. Cleanup

Launch Stack

To launch the stack without a KeyName:

aws cloudformation create-stack --stack-name ecs-spot-demo --template-body file://ecs-spot-demo.yml --capabilities CAPABILITY_IAM

If you would like to launch the stack with an ssh key. Here are the commands:

# Quick way to grab first keypair on the AWS account.
KEY_NAME=$(aws ec2 describe-key-pairs | jq -r '.KeyPairs[0].KeyName')

# Create a parameters file for the one required parameter in this template
cat <<EOL > parameters.json
[
  {
    "ParameterKey": "KeyName",
    "ParameterValue": "$KEY_NAME"
  }
]
EOL

# Launch the stack
aws cloudformation create-stack --stack-name ecs-spot-demo --template-body file://ecs-spot-demo.yml --parameters file://parameters.json --capabilities CAPABILITY_IAM

Deploy Demo App

First let's create the ECR repo and set some variables we'll need:

ECR_REPO=$(aws ecr create-repository --repository-name demo/sinatra | jq -r '.repository.repositoryUri')
VPC_ID=$(aws ec2 describe-vpcs --filters Name=tag:Name,Values="demo vpc" | jq -r '.Vpcs[].VpcId')

Now we're ready to clone the demo repo and deploy an sample app to ECS with ufo. Note, you'll need Docker installed.

git clone https://github.com/tongueroo/demo-ufo.git demo
cd demo
ufo init --image $ECR_REPO --vpc-id $VPC_ID
ufo current --service demo-web
ufo ship # deploys to ECS on the Spot Fleet cluster

Cleanup

To clean up. First, delete the ECS service.

cd demo # demo project
ufo destroy

Delete the ECR repo:

IMAGES=$(aws ecr list-images --repository-name demo/sinatra | jq -r '.imageIds[].imageDigest')
for i in $IMAGES; do aws ecr batch-delete-image --repository-name demo/sinatra --image-ids imageDigest=$i ; done
aws ecr delete-repository --repository-name demo/sinatra

Delete the infrastructure CloudFormation stack:

aws cloudformation delete-stack --stack-name ecs-spot-demo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.