To retrieve your instance id use a combination of AWS metadata tool and the new Tag API to retrieve the tags for the instance.
After you have installed ec2-metadata and ec2-describe-tags, use this example shell command to retrieve your current instances name. In this example, “Name=demo” is the tag you have to use.
Assumes EC2_PRIVATE_KEY and EC2_CERT environment variables are set.
ec2-describe-tags \
--filter "resource-type=instance" \
--filter "resource-id=$(ec2-metadata -i | cut -d ' ' -f2)" \
--filter "key=Name" | cut -f5
This returns demo.