Created
March 22, 2022 17:46
-
-
Save luiarthur/c9e8d57be229e965d5116ff7ade090cc to your computer and use it in GitHub Desktop.
start a stopped AWS EC2 instances
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 | |
# GSOC instance. | |
aws_instance_id=i-01234567d # dummy id. | |
# Start a stopped aws ec2 instance. | |
alias start_aws_instance="aws ec2 start-instances --instance-ids $gsoc_id" | |
# Stop a running aws ec2 instance. | |
alias stpo_aws_instance="aws ec2 stop-instances --instance-ids $gsoc_id" | |
# SSH into that instance. | |
ssh_gsoc() { | |
# Get the public IP address of the instance. | |
# This is needed as a restart of the instance changes the IP address. | |
gsoc_ip=`aws ec2 describe-instances --instance-ids $gsoc_id --query "Reservations[*].Instances[*].PublicIpAddress" --output text` | |
# SSh into the instance using the public IP address. | |
ssh ubuntu@${gsoc_ip} -L 7111:localhost:7111 -i path/to/instance-name.pem | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment