Skip to content

@andsens /benchmark-ec2-boottime.sh
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Starts a single instance and measures the time until SSH connectivity
#!/bin/bash -e
# These need to be set.
#export EC2_HOME="/path/to/ec2-api-tools"
#export AWS_ACCESS_KEY='XXXXXXXXXXXXXXXXXXXX'
#export AWS_SECRET_KEY='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
#export PATH="$PATH:${EC2_HOME}/bin"
ami_id='ami-123abc12'
availability_zone='eu-west-1a'
keypair="johndoe@example.com"
instance_type="t1.micro"
start_time=`date +%s`
instance_id=`ec2-run-instances "$ami_id" \
--availability-zone "$availability_zone" \
--instance-type "$instance_type" \
--key "$keypair" \
| grep 'INSTANCE' | awk '{print $2}'`
printf "Instance ID: %s\n" "$instance_id"
sleep 5
while [ 1 ]; do
instance_uri=`ec2-describe-instances --filter "instance-id=$instance_id" | grep "INSTANCE" | awk '{print $4}'`
if [[ -n "$instance_uri" && "$instance_uri" != 'pending' ]]; then
break
fi
sleep 1
done
if [[ ! "$instance_uri" =~ "compute.amazonaws.com" ]]; then
printf "'$instance_uri' does not look like an instance URI\n"
exit 1
fi
printf "Instance URI: %s\n" "$instance_uri"
ssh_cmd="ssh root@$instance_uri -o StrictHostKeyChecking=no -o ConnectTimeout=1 echo 'test' 2>/dev/null || true"
while [ -z "$cmd_status" ]; do
printf '.'
sleep 1
cmd_status=`eval $ssh_cmd`
done
end_time=`date +%s`
ec2-terminate-instances "$instance_id" > /dev/null
bootup_time="$(($end_time - $start_time))"
printf "Bootup Time: %i seconds\n" "$bootup_time"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.