Issue
If one launches 5 EC2 instances in a single go, is there a way to uniquely ID each instance with a pre-known ID (e.g. 1, 2, 3, 4, 5) in the User data setting of Step 3: Configure Instance Details?
e.g. User data:
#!/bin/bash
for i in {1..5}
do
#assign a unique number 1 through 5 to this instance
echo $id > $dir
done
Solution
Yes. There is a field called ami-launch-index
that varies for each instance that is launched, starting with zero.
You can obtain it with:
curl http://169.254.169.254/latest/meta-data/ami-launch-index
For details, see: AMI launch index value - Amazon Elastic Compute Cloud
Answered By - John Rotenstein