Skip to content

Instantly share code, notes, and snippets.

@faermanj
Created March 12, 2024 13:56
Show Gist options
  • Save faermanj/5bf1f7f3187cd41e00da365547931d29 to your computer and use it in GitHub Desktop.
Save faermanj/5bf1f7f3187cd41e00da365547931d29 to your computer and use it in GitHub Desktop.
instance self shutdown
#!/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