Skip to content

Instantly share code, notes, and snippets.

@RichardBronosky
Created August 5, 2019 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichardBronosky/d089e421c12095e9456ea0088c6c3261 to your computer and use it in GitHub Desktop.
Save RichardBronosky/d089e421c12095e9456ea0088c6c3261 to your computer and use it in GitHub Desktop.
Send EC2 launch notification to Slack webhook complete with connection command
# This functionality uses https://slack.com/apps/A0F7XDUAZ-incoming-webhooks?next_id=0
# Replace the 3 hashes in the next line with those from your webhook
slack(){ curl -d 'payload={"text": "'"$@"'"}' https://hooks.slack.com/services/HASH/HASH/HASH; }
msg_string='Instance \\"hack\\" came online. To connect:\n`%s`\nor:\n`%s`\n'
key="$(curl -s http://169.254.169.254/latest/meta-data/public-keys/ | awk -F '=' 'NR=1{print $2}')"
user="$(id -nu 1000)"
con_string="ssh -i ~/.ssh/$key.pem $user@%s"
private_host="$(hostname -f)"
public_host="$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4)"
slack "$(printf "$msg_string" "$(printf "$con_string" "$private_host")" "$(printf "$con_string" "$public_host")")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment