airdata
airdata

Reputation: 641

How to find Security Group ID in ec2 metadata?

I'm trying to find security group ID in metadata, but there is only a name of the group.

The get the name with curl like this:

curl http://169.254.169.254/latest/meta-data/security-groups/

RESULT

some-secgroup-name

I need the ID like this one sg-1234567911

Any Idea how to I find in metadata (whitout CLI)?

Upvotes: 2

Views: 1327

Answers (1)

rdas
rdas

Reputation: 21275

You'll need the MAC address of the instance. To obtain that you can do a curl using the metadata url:

http://169.254.169.254/latest/meta-data/mac

Once you have that, you can get the security groups from the network section:

http://169.254.169.254/latest/meta-data/network/interfaces/macs/<your_mac>/security-group-ids

Ref: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html#instancedata-data-categories

Upvotes: 6

Related Questions