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
In the question you have mentioned the user as root, one thing I should mention is that the instance ID is not dependent on the user.
For Node developers,
On Ubuntu you can:
And then you can:
You can get most of the metadata associated with the instance this way:
For all ec2 machines, the instance-id can be found in file:
You can also get instance id by running the following command:
The latest Java SDK has
EC2MetadataUtils
:In Java:
In Scala:
Alternative approach for PHP:
That will provide a lot of data about the instance, all nicely packed in an array, no external dependencies. As it's a request that never failed or delayed for me it should be safe to do it that way, otherwise I'd go for curl()
Use the
/dynamic/instance-identity/document
URL if you also need to query more than just your instance ID.wget -q -O - http://169.254.169.254/latest/dynamic/instance-identity/document
This will get you JSON data such as this - with only a single request.