Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.