Skip to content

Instantly share code, notes, and snippets.

@faermanj
Created March 12, 2024 13:56

Revisions

  1. faermanj created this gist Mar 12, 2024.
    15 changes: 15 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    #!/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"