Created
February 18, 2020 11:10
-
-
Save varunchandak/e438a4565fbb5f82a210894bfd917d68 to your computer and use it in GitHub Desktop.
Get Instance Public IP on Email on new instance launch.
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
#!/bin/bash | |
export AWS_ACCOUNT_ID="<ENTER_ACCOUNT_ID>" | |
export AWS_DEFAULT_REGION="ap-south-1" | |
SNS_ARN="arn:aws:sns:ap-south-1:$AWS_ACCOUNT_ID:GetPublicIP" | |
PUBIPADDRESS="$(curl -s icanhazip.com)" | |
INST_NAME="$(aws ec2 describe-instances --filters Name=ip-address,Values="$PUBIPADDRESS" --query 'Reservations[*].Instances[*].Tags[?Key==`Name`].Value')" | |
aws sns publish \ | |
--topic-arn "$SNS_ARN" \ | |
--message "$INST_NAME | $PUBIPADDRESS" \ | |
--subject "$INST_NAME | $PUBIPADDRESS" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment