Skip to content

Commit

Permalink
#4990 clean up create and delete all PoC
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-a-dunlap committed Sep 11, 2018
1 parent 8db31c9 commit 9d04a2b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash -x
#Initially Referred to this doc: https://docs.aws.amazon.com/cli/latest/userguide/tutorial-ec2-ubuntu.html

DEPLOY_FILE=dataverse_deploy_info.txt
Expand Down Expand Up @@ -26,9 +26,6 @@ else
echo "*Security group already exists."
fi

#Create key pair. Does this pem need to be saved or just held temporarilly?
# - Probably held, we probably need another script to blow away our spinned-up ec2 instance
# - Should attach the branch name to the key
echo "*Checking for existing key pair"
if ! [ -f devenv-key.pem ]; then
echo "*Creating key pair"
Expand All @@ -43,14 +40,13 @@ else
echo "*Key pair alraedy exists."
fi

#AMI ID acquired by this (very slow) query Sept 10th 2018
#AMI ID for centos7 acquired by this (very slow) query Sept 10th 2018
#This does not need to be run every time, leaving it in here so it is remembered
#aws ec2 describe-images --owners 'aws-marketplace' --filters 'Name=product-code,Values=aw0evgkw8e5c1q413zgy5pjce' --query 'sort_by(Images, &CreationDate)[-1].[ImageId]' --output 'text'

#The AMI ID only works for region us-east-1, for now just forcing that
#Using this image ID a 1-time requires subscription per root account, which was done through the UI
echo "*Creating ec2 instance"
#INSTACE_ID=$(aws ec2 run-instances --image-id ami-9887c6e7 --security-groups devenv-sg --count 1 --instance-type t2.nano --key-name devenv-key --query 'Instances[0].InstanceId' --block-device-mappings file://ec2-device-mapping.json | tr -d \")
INSTACE_ID=$(aws ec2 run-instances --image-id ami-9887c6e7 --security-groups devenv-sg --count 1 --instance-type t2.nano --key-name devenv-key --query 'Instances[0].InstanceId' --block-device-mappings '[ { "DeviceName": "/dev/sda1", "Ebs": { "DeleteOnTermination": true } } ]' | tr -d \")
echo "Instance ID: "$INSTACE_ID
echo "*End creating EC2 instance"
Expand All @@ -65,12 +61,6 @@ rm -rf $DEPLOY_FILE

echo "New EC2 instance created at $PUBLIC_DNS"

#ssh -i devenv-key.pem centos@$PUBLIC_DNS

#PUBLIC_IP=$()

#echo $PUBLIC_IP

#Outstanding needs:
# - Delete Script
# - Correct ec2 specs for our needs
Expand Down
11 changes: 11 additions & 0 deletions scripts/installer/ec2-destroy-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

#This script gets all the instances from ec2 and sends terminate to them
#Its pretty basic and probably shouldn't be trusted at this point. Namely:
# - You can kill instances other people are using
# - It will try to kill instances that are already dead, which makes output hard to read
# - If it fails for some reason it's hard to tell the script didn't work right

INSTANCES=$(aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId]' --output text)

aws ec2 terminate-instances --instance-ids $INSTANCES

0 comments on commit 9d04a2b

Please sign in to comment.