hey arjun, i actually worked on a few scripts to automate these steps over the weekend. it’s kind of like rolling your own crestle — i wanted to do that so i could use the $500 AWS credits we got. sharing these here in case anyone else wants to use these.
basically, the end goal is to be able to
- start my servers with
aws-start
- stop my servers with
aws-end
- ssh into my servers with
aws-ssh
- check whether my servers are running with
aws-check
Both my servers are connected to the same EBS volume, so I work on a jupyter notebook until I’m pretty sure everything kinda works, then I start the GPU and run the experiments.
the only setup you need is:
- I started a p2 and m4 via the console and then got their instance-id numbers.
- I also got the volume-id from the console of the EBS drive that comes attached to either of them. I unmounted the other.
for aws-check
--> save the following to check_aws.sh
and alias it in your bash_rc / bash_profile. do similar things for the commands below.
#!/bin/bash
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[Placement.AvailabilityZone, State.Name, InstanceId, InstanceType]' --output text
for aws-start
-->
#!/bin/bash
aws-check
read -p "Start? (cpu/gpu): " AWS_INSTANCE_TYPE
if [ "$AWS_INSTANCE_TYPE" == "cpu" ]
then
export AWS_INSTANCE_ID=$AWS_CPU_ID
fi
if [ "$AWS_INSTANCE_TYPE" == "gpu" ]
then
export AWS_INSTANCE_ID=$AWS_GPU_ID
fi
aws ec2 wait volume-available --volume-ids $EBS_VOL_ID
aws ec2 attach-volume --device /dev/sda1 --volume-id $EBS_VOL_ID --instance-id $AWS_INSTANCE_ID
aws ec2 start-instances --instance-ids $AWS_INSTANCE_ID
aws ec2 wait instance-running --instance-ids $AWS_INSTANCE_ID
aws-ssh
for aws-ssh
-->
#!/bin/bash
export AWS_PUBLIC_DNS=$(aws ec2 describe-instances --instance-ids $AWS_INSTANCE_ID --filters "Name=instance-id,Values='$AWS_INSTANCE_ID'" --query 'Reservations[*].Instances[*].PublicDnsName' --output text)
ssh -L localhost:8888:localhost:8888 -i <key-file.pem> ubuntu@$AWS_PUBLIC_DNS -o "StrictHostKeyChecking no"
for aws-end
-->
#!/bin/bash
aws-check
read -p "Stop? (cpu/gpu): " AWS_INSTANCE_TYPE
if [ "$AWS_INSTANCE_TYPE" == "cpu" ]
then
export AWS_INSTANCE_ID=$AWS_CPU_ID
fi
if [ "$AWS_INSTANCE_TYPE" == "gpu" ]
then
export AWS_INSTANCE_ID=$AWS_GPU_ID
fi
aws ec2 stop-instances --instance-ids $AWS_INSTANCE_ID
aws ec2 wait instance-stopped --instance-id $AWS_INSTANCE_ID
aws ec2 detach-volume --volume-id $EBS_VOL_ID
aws ec2 wait volume-available --volume-id $EBS_VOL_ID
echo $AWS_INSTANCE_TYPE stopped.
Remember to also export your GPU instance ID, CPU instance ID and EBS volume ID in your bash_profile file.
It’s not the best it could be. These are still all on-demand instances. Crestle is great because it manages provision spot instances for you. But it got the headache of remembering to unmount my EBS when I was switching between my GPU and CPU instances out of the way, so it’s a start.
Hope these help!