Skip to content

Instantly share code, notes, and snippets.

@brainstorm
Last active Nov 7, 2020
Embed
What would you like to do?
Poor man's vscode on AWS launch script
#!/bin/bash -x
## TODO:
# *** Just use this instead of this pestilent bash script: https://pypi.org/project/cdk-spot-one/ ***
# Monitor when and if the spot request is cancelled by AWS. Default shutdown behaviour is Stop so filesystems are kept intact, only connections die.
# 1. Launches instance w/ launch template and public VPC
# 2. Waits for spot request status to change to active/fulfilled
# 3. Gets public ip address for instance
instance_id=`aws ec2 run-instances --launch-template LaunchTemplateId=lt-08b57fe5e43af9d9b --subnet=subnet-0fab038b0341872f1 --query 'Instances[*]. InstanceId' --output text`
echo "Launched instance with id: $instance_id\n"
aws ec2 wait spot-instance-request-fulfilled --filters Name=state,Values=active
while [[ $found != $instance_id ]];
do
sleep 1
found=`aws ec2 describe-instances --query 'Reservations[*].Instances[*].InstanceId' --output text | grep $instance_id`
done
public_dns_name=`aws ec2 describe-instances --query "Reservations[*].Instances[?InstanceId=='$instance_id'].PublicDnsName" --output text`
echo "Public DNS name is: $public_dns_name"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment