From fe5cb90fc10f0cf8df7a3499198ae833bf18f437 Mon Sep 17 00:00:00 2001 From: Danny Thomas Date: Fri, 28 Oct 2016 14:54:20 -0700 Subject: [PATCH] Externalise instance type --- ec2gaming-instance.sh | 4 ++-- ec2gaming-price.sh | 2 +- ec2gaming-start.sh | 4 ++-- ec2gaming.cfg | 1 + 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ec2gaming-instance.sh b/ec2gaming-instance.sh index ff6b5d6..c951789 100755 --- a/ec2gaming-instance.sh +++ b/ec2gaming-instance.sh @@ -2,9 +2,9 @@ source "$(dirname "$0")/ec2gaming.header" # Verify that the gaming stane actually exists (and that there's only one) -INSTANCES=$(aws ec2 describe-instances --filters Name=instance-state-code,Values=16 Name=instance-type,Values=g2.2xlarge) +INSTANCES=$(aws ec2 describe-instances --filters Name=instance-state-code,Values=16 Name=instance-type,Values="$INSTANCE_TYPE") if [ "$(echo "$INSTANCES" | jq '.Reservations | length')" -ne "1" ]; then - >&2 echo "didn't find an instance or there wasn't exactly one g2.2xlarge instance" + >&2 echo "didn't find an instance or there wasn't exactly one $INSTANCE_TYPE instance" exit 1 fi echo "$INSTANCES" | jq --raw-output '.Reservations[0].Instances[0].InstanceId' diff --git a/ec2gaming-price.sh b/ec2gaming-price.sh index 23c911c..d8946a8 100755 --- a/ec2gaming-price.sh +++ b/ec2gaming-price.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash source "$(dirname "$0")/ec2gaming.header" -aws ec2 describe-spot-price-history --instance-types g2.2xlarge --product-descriptions "Windows" --start-time `date +%s` | jq --raw-output '.SpotPriceHistory|=sort_by(.SpotPrice)|first(.SpotPriceHistory[].SpotPrice), first(.SpotPriceHistory[].AvailabilityZone)' +aws ec2 describe-spot-price-history --instance-types "$INSTANCE_TYPE" --product-descriptions "Windows" --start-time `date +%s` | jq --raw-output '.SpotPriceHistory|=sort_by(.SpotPrice)|first(.SpotPriceHistory[].SpotPrice), first(.SpotPriceHistory[].AvailabilityZone)' diff --git a/ec2gaming-start.sh b/ec2gaming-start.sh index 0b39883..fa34a90 100755 --- a/ec2gaming-start.sh +++ b/ec2gaming-start.sh @@ -3,7 +3,7 @@ source "$(dirname "$0")/ec2gaming.header" BOOTSTRAP=0 -echo -n "Getting lowest g2.2xlarge bid... " +echo -n "Getting lowest $INSTANCE_TYPE bid... " PRICE_AND_ZONE=($(./ec2gaming-price.sh)) PRICE=${PRICE_AND_ZONE[0]} ZONE=${PRICE_AND_ZONE[1]} @@ -44,7 +44,7 @@ SPOT_INSTANCE_ID=$(aws ec2 request-spot-instances --spot-price "$FINAL_SPOT_PRIC { \"SecurityGroupIds\": [\"$EC2_SECURITY_GROUP_ID\"], \"ImageId\": \"$AMI_ID\", - \"InstanceType\": \"g2.2xlarge\", + \"InstanceType\": \"$INSTANCE_TYPE\", \"Placement\": { \"AvailabilityZone\": \"$ZONE\" } diff --git a/ec2gaming.cfg b/ec2gaming.cfg index dc5ffc5..fdd2049 100644 --- a/ec2gaming.cfg +++ b/ec2gaming.cfg @@ -1 +1,2 @@ +INSTANCE_TYPE="g2.2xlarge" SPOT_PRICE_BUFFER="0.10"