Created
March 12, 2024 13:56
-
-
Save faermanj/5bf1f7f3187cd41e00da365547931d29 to your computer and use it in GitHub Desktop.
instance self shutdown
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
#!/usr/bin/env bash | |
set -ex | |
# This script is used by the bastion host to stop itself | |
# | |
TOKEN=$(curl -s \ | |
-X PUT "http://169.254.169.254/latest/api/token" \ | |
-H "X-aws-ec2-metadata-token-ttl-seconds: 21600") | |
ID=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" \ | |
-s http://169.254.169.254/latest/meta-data/instance-id) | |
aws ec2 stop-instances --instance-id $ID | |
init 0 | |
echo "instance [$ID] stopping" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment