Created
May 20, 2021 07:27
-
-
Save kritro/ce48742df92b15e684b897335cb92b9a to your computer and use it in GitHub Desktop.
This file contains 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
$AWS_AVAIL_ZONE=(Invoke-WebRequest http://169.254.169.254/latest/meta-data/placement/availability-zone -UseBasicParsing).Content | |
$AWS_REGION=$AWS_AVAIL_ZONE.Substring(0,$AWS_AVAIL_ZONE.length-1) | |
$AWS_INSTANCE_ID=(Invoke-WebRequest http://169.254.169.254/latest/meta-data/instance-id -UseBasicParsing).Content | |
$ROOT_VOLUME_IDS=((Get-EC2Instance -Region $AWS_REGION -InstanceId $AWS_INSTANCE_ID).Instances.BlockDeviceMappings | where-object DeviceName -match '/dev/sda1').Ebs.VolumeId | |
$instanceTags = Get-EC2Tag -Filter @{ Name="resource-id"; Values=$AWS_INSTANCE_ID} | |
$InstanceTagName = $instanceTags.Where({$_.Key -eq "Name"}).Value | |
$tag = New-Object Amazon.EC2.Model.Tag | |
$tag.key = "Name" | |
$tag.value = $InstanceTagName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment