Created
August 5, 2019 16:53
-
-
Save RichardBronosky/d089e421c12095e9456ea0088c6c3261 to your computer and use it in GitHub Desktop.
Send EC2 launch notification to Slack webhook complete with connection command
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
# 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