In progress ec2 script.

This commit is contained in:
Russell Jurney 2013-07-01 19:34:43 -07:00
parent 8a1512ae4b
commit c1f6c0ab4a
1 changed files with 15 additions and 12 deletions

27
examples/bin/run_ec2.sh Normal file → Executable file
View File

@ -1,17 +1,19 @@
# Before running, you will need to download the EC2 tools from http://aws.amazon.com/developertools/351
# and then setup your EC2_HOME and PATH variables (or similar):
#
# unzip ec2-api-tools.zip
# cd ec2-api-tools-*
#
# # Setup environment for ec2-api-tools
# export EC2_HOME=`pwd`
# echo "EC2_HOME=`pwd`" >> ~/.bash_profile
# echo 'export PATH=$PATH:$EC2_HOME/bin' >> ~/.bash_profile
# source ~/.bash_profile
# export EC2_HOME=/path/to/ec2-api-tools-1.6.7.4/
# export PATH=$PATH:$EC2_HOME/bin
AWS_ACCESS_KEY=
AWS_SECRET_KEY=
export AWS_ACCESS_KEY=AKIAI42EC3TWOGWFXZHQ
export AWS_SECRET_KEY=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
# Check for ec2 commands we require and die if they're missing
type ec2-create-keypair >/dev/null 2>&1 || { echo >&2 "I require ec2-create-keypair but it's not installed. Aborting."; exit 1; }
type ec2-create-group >/dev/null 2>&1 || { echo >&2 "I require ec2-create-group but it's not installed. Aborting."; exit 1; }
type ec2-authorize >/dev/null 2>&1 || { echo >&2 "I require ec2-authorize but it's not installed. Aborting."; exit 1; }
type ec2-run-instances >/dev/null 2>&1 || { echo >&2 "I require ec2-run-instances but it's not installed. Aborting."; exit 1; }
type ec2-describe-instances >/dev/null 2>&1 || { echo >&2 "I require ec2-describe-instances but it's not installed. Aborting."; exit 1; }
# Create a keypair for our servers
ec2-create-keypair druid-keypair > druid-keypair
@ -29,11 +31,12 @@ ec2-authorize druid-group -P tcp -p 1-65535 -o druid-group
ec2-authorize druid-group -P udp -p 1-65535 -o druid-group
# Use ami ami-e7582d8e - Alestic Ubuntu 12.04 us-east
ec2-run-instances ami-e7582d8e -n 1 -g druid-group -k druid-keypair --instance-type m1.small
ec2-describe-instances
INSTANCE_ID=$(ec2-run-instances ami-e7582d8e -n 1 -g druid-group -k druid-keypair --instance-type m1.small| awk '/INSTANCE/{print $2}')
ec2-describe-instances|grep INSTANCE|grep $INSTANCE_ID
sleep 30
# Get hostname and ssh with the key we created, and ssh there
INSTANCE_ADDRESS=`ec2-describe-instances|grep 'INSTANCE'|cut -f4` && echo $INSTANCE_ADDRESS
INSTANCE_ADDRESS=`ec2-describe-instances|grep 'INSTANCE'|grep $INSTANCE_ID|cut -f4` && echo $INSTANCE_ADDRESS
ssh -i ~/.ssh/druid-keypair -o StrictHostKeyChecking=no ubuntu@${INSTANCE_ADDRESS} <<\EOI
# Install dependencies - mysql and Java, and setup druid db
export DEBIAN_FRONTEND=noninteractive