0 votes
1 view
in AWS by (18.2k points)

I'm trying to set up a means to register an instance in route53 automatically when the instance is created.

The article uses ec2-metadata to get the instance-id and the hostname. I'm wondering if there is a way, using bash within the instance, to get the instance Name instead. ec2-metadata only seems to show the instance-id.

1 Answer

0 votes
by (42.4k points)

First, using the instance-id:

AWS_INSTANCE_ID=`curl -s http://169.254.169.254/latest/meta-data/instance-id`

Use the below statement to get the instance name:

EC2_NAME=$(aws ec2 describe-tags --region $REGION --filters "Name=resource-id,Values=$AWS_INSTANCE_ID" "Name=key,Values=Name" --output text | cut -f5)

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...