Giter Site home page Giter Site logo

spot-lab's Introduction

[LAB] JP's EC2 Spot Lab

Verify latest Amazon Linux 2 AMI

aws ec2 describe-images --owners amazon --filters 'Name=name,Values=amzn2-ami-hvm-2.0.????????-x86_64-gp2' 'Name=state,Values=available' --output json | jq -r '.Images | sort_by(.CreationDate) | last(.[]).ImageId'

Replace latest AMI-ID to to ec2-launch-template.json and execute the following command to create launch template

aws ec2 create-launch-template --cli-input-json file://launch-template.json

Create ASG with Lowest Price as spot allocation strategy

aws autoscaling create-auto-scaling-group --cli-input-json file://asg-lowest-price-n-1.json

Create ASG with Capacity Optimized as spot allocation strategy

aws autoscaling create-auto-scaling-group --cli-input-json file://asg-capacity-optimized.json

Run the following script to query lowest price asg group

while read i a p m; do s=$(aws ec2 describe-spot-price-history --instance-types $i --availability-zone $a --product-descriptions "Linux/UNIX (Amazon VPC)" --start-time $(date +%FT%TZ) --end-time $(date +%FT%TZ) --output text); echo -e $s'\t'$m | awk -F'\t' '{print $2, $3, $7, $5, ($7-$5)/$7*100}'; done < <(for sir in $(aws ec2 describe-instances --filters "Name=tag:aws:autoscaling:groupName,Values=lowest-price-n-1" "Name=instance-state-name,Values=running" "Name=instance-lifecycle,Values=spot" --query 'Reservations[*].Instances[*].[SpotInstanceRequestId]' --output text); do aws ec2 describe-spot-instance-requests --spot-instance-request-ids $sir --query 'SpotInstanceRequests[*].[LaunchSpecification.InstanceType, LaunchedAvailabilityZone, ProductDescription, SpotPrice]' --output text; done)

Run the following script to query capacity optimized asg group

while read i a p m; do s=$(aws ec2 describe-spot-price-history --instance-types $i --availability-zone $a --product-descriptions "Linux/UNIX (Amazon VPC)" --start-time $(date +%FT%TZ) --end-time $(date +%FT%TZ) --output text); echo -e $s'\t'$m | awk -F'\t' '{print $2, $3, $7, $5, ($7-$5)/$7*100}'; done < <(for sir in $(aws ec2 describe-instances --filters "Name=tag:aws:autoscaling:groupName,Values=capacity-optimized" "Name=instance-state-name,Values=running" "Name=instance-lifecycle,Values=spot" --query 'Reservations[*].Instances[*].[SpotInstanceRequestId]' --output text); do aws ec2 describe-spot-instance-requests --spot-instance-request-ids $sir --query 'SpotInstanceRequests[*].[LaunchSpecification.InstanceType, LaunchedAvailabilityZone, ProductDescription, SpotPrice]' --output text; done)

After you are done with the lab, run the following clean up the resources created

aws autoscaling delete-auto-scaling-group --auto-scaling-group-name lowest-price-n-1 --force-delete
aws autoscaling delete-auto-scaling-group --auto-scaling-group-name capacity-optimized --force-delete
aws ec2 delete-launch-template --launch-template-id [ADD TEMPLATE ID] --region us-east-1

spot-lab's People

Contributors

jpbueno avatar dgomesbr avatar

Stargazers

Daniel Serodio avatar  avatar

Watchers

James Cloos avatar  avatar

Forkers

dgomesbr

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.