Last active
November 7, 2020 13:44
-
-
Save brainstorm/7f333919285420b73cf756d854564c47 to your computer and use it in GitHub Desktop.
Poor man's vscode on AWS launch script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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