How can I find out the instance id
of an ec2 instance from within the ec2 instance?
相关问题
- How to generate 12 digit unique number in redshift
- Use awslogs with kubernetes 'natively'
- JQ: Select when attribute value exists in a bash a
- Assume/switch role in aws toolkit for eclipse 2.0
- 'no SavedModel bundles found!' on tensorfl
相关文章
- Right way to deploy Rails + Puma + Postgres app to
- how many objects are returned by aws s3api list-ob
- AWS S3 in rails - how to set the s3_signature_vers
- Passthrough input to output in AWS Step Functions
- I cannot locate production log files on Elastic Be
- ImportError: cannot import name 'joblib' f
- Static IP for Auto Scale in AWS
- Step function exceeding the maximum number of char
For C++ (using cURL):
For Python:
which boils down to the one-liner:
Instead of local_hostname you could also use public_hostname, or:
on AWS Linux:
ec2-metadata --instance-id | cut -d " " -f 2
Output:
i-33400429
Using in variables:
If you wish to get the all available instance id list using python here is the code:
To get the instance metadata use
get -q -O - http://169.254.169.254/latest/meta-data/instance-id
On Amazon Linux AMIs you can do:
Or, on Ubuntu and some other linux flavours,
ec2metadata --instance-id
(This command may not be installed by default on ubuntu, but you can add it withsudo apt-get install cloud-utils
)As its name suggests, you can use the command to get other useful metadata too.