Created
September 3, 2024 15:53
-
-
Save jcefoli/780579002525412557d4d02aeb39206b to your computer and use it in GitHub Desktop.
AWS IMDSv2 Metadata Examples in Powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Required for auth | |
$imdsv2Token = Invoke-RestMethod -Method PUT -Uri "http://169.254.169.254/latest/api/token" -Headers @{"X-aws-ec2-metadata-token-ttl-seconds" = "30"} | |
# Get Instance ID | |
$instanceId = Invoke-RestMethod -Uri "http://169.254.169.254/latest/meta-data/instance-id" -Headers @{"X-aws-ec2-metadata-token" = "$imdsv2Token"} | |
# Get Tag on Current Instance | |
$instanceId = Invoke-RestMethod -Uri "http://169.254.169.254/latest/meta-data/instance-id" -Headers @{"X-aws-ec2-metadata-token" = "$imdsv2Token"} | |
$ec2Tag = (Get-EC2Tag -Filter @{Name = "resource-type"; Values = "instance" }, @{Name = "resource-id"; Values = $instanceId }, @{Name = 'tag:t_something'; Values = "*" }).Value | |
# Get current AWS Region | |
$region = (Invoke-RestMethod -Uri "http://169.254.169.254/latest/dynamic/instance-identity/document" -Headers @{"X-aws-ec2-metadata-token" = "$imdsv2Token"}).Region |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment