I use aws ec2 userdata with windows powershell scripts. I need instance bootstrapping. My idea is:
I have tried to get version tag value in userdata. I checked aws http api. It can't return tags. I wrote simple powershell scripts:
$instanceId = (New-Object System.Net.WebClient).DownloadString("http://169.254.169.254/latest/meta-data/instance-id")
aws ec2 describe-tags --filters $filter --query 'Tags[*]'
I can get instance Id with aws http api. I can't get instance tags because AWS ec2 userdata can't start "aws.exe".
This script is correct - it is manually run before the instance is started.
Note: "aws" is "aws.exe" (https://aws.amazon.com/cli/)
I resolve it, my problem is using aws cli . I use powershell api and fix it.
$instanceId = (New-Object System.Net.WebClient).DownloadString("http://169.254.169.254/latest/meta-data/instance-id")
$versionTag = Get-EC2Tag | ` Where-Object {$_.ResourceId -eq $instanceId -and $_.Key -eq 'Version'}