https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html

 

Retrieve instance metadata - Amazon Elastic Compute Cloud

For Instances built on the Nitro System, IMDS can be reached from your own network when a network appliance within your VPC, such as a virtual router, forwards packets to the IMDS address, and the default source/destination check on the instance is disable

docs.aws.amazon.com

aws ec2 인스턴스 정보를 가져오고 싶을 때 메타데이터를 이용하면 된다.

$ curl http://169.254.169.254/latest/meta-data/
$ curl http://[fd00:ec2::254]/latest/meta-data/
ami-id
ami-launch-index
ami-manifest-path
block-device-mapping/
events/
hostname
iam/
instance-action
instance-id
instance-type
local-hostname
local-ipv4
mac
metrics/
network/
placement/
profile
public-hostname
public-ipv4
public-keys/
reservation-id
security-groups
services/

curl 같은 프로그램으로 위와 같은 IPv4 IPv6 url 을 입력하면 된다.

$ curl -sL http://169.254.169.254/latest/meta-data/public-ipv4
24.xxx.xxx.xxx

public-ipv4 나 instance-type 를 가끔 사용하게 된다.

https://stackoverflow.com/questions/625644/how-to-get-the-instance-id-from-within-an-ec2-instance

 

How to get the instance id from within an ec2 instance?

How can I find out the instance id of an ec2 instance from within the ec2 instance?

stackoverflow.com

curl 대신에 ec2-metadata 라는 콘솔 명령어를 사용할 수도 있다.

728x90

+ Recent posts