Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #/bin/sh
- export AWS_PROFILE=<profile>
- MY_IP=$(curl -s ifconfig.co)
- INSTANCE_ID=<instance>
- SG=<sg>
- if [[ $1 = "start" ]]; then
- echo Starting $INSTANCE_ID.
- aws ec2 start-instances --instance-ids $INSTANCE_ID > /dev/null
- aws ec2 wait instance-running --instance-ids $INSTANCE_ID
- echo Instance running.
- aws ec2 authorize-security-group-ingress --group-id $SG --port 8080 --cidr $MY_IP/32 --protocol tcp > /dev/null
- if [ $? -eq 0 ]; then
- echo New security group rule added to allow traffic from $MY_IP.
- else
- echo Security group already allows traffic from $MY_IP.
- fi
- sleep 15
- WW=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query "Reservations[0].Instances[0].PublicIpAddress" --output text)
- echo Instance IP: $WW
- start http://$WW:8080
- elif [[ $1 = "stop" ]]; then
- aws ec2 stop-instances --instance-ids $INSTANCE_ID > /dev/null
- echo Stopping instance.
- else
- STATUS=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query "Reservations[0].Instances[0].State.Name" --output text)
- echo Instance $INSTANCE_ID is $STATUS.
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement