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 powershell people:
FWIW I wrote a FUSE filesystem to provide access to the EC2 metadata service: https://bitbucket.org/dgc/ec2mdfs . I run this on all custom AMIs; it allows me to use this idiom: cat /ec2/meta-data/ami-id
For PHP:
Edit per @John
Simply check the
var/lib/cloud/instance
symlink, it should point to/var/lib/cloud/instances/{instance-id}
where{instance_id}
is your instance-id.You can just make a HTTP request to GET any Metadata by passing the your metadata parameters.
or
You won't be billed for HTTP requests to get Metadata and Userdata.
Else
You can use EC2 Instance Metadata Query Tool which is a simple bash script that uses curl to query the EC2 instance Metadata from within a running EC2 instance as mentioned in documentation.
Download the tool:
now run command to get required data.
Refer:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
https://aws.amazon.com/items/1825?externalID=1825
Happy To Help.. :)
See the EC2 documentation on the subject.
Run:
If you need programatic access to the instance ID from within a script,
An example of a more advanced use (retrieve instance ID as well as availability zone and region, etc.):
You may also use
curl
instead ofwget
, depending on what is installed on your platform.