I have to query my AWS account to find latest created volume with specific tags and should have it attached to running EC2 instance. How do I achieve this using aws cli and powershell?
I was using below powershell script and aws cli to achieve this, But I was not able to find out exact query to get latest volume id using aws cli command to replace variable $volumeid. Any help would be appreciated.
$volumeid = "aws ec2 describe-volumes --region us-east-1 --filters Name=tag:Application_Name,Values=APPone Name=tag:Name,Values=APP_test --query "Volumes[*].{ID:VolumeId}"
$instanceId = (New-Object System.Net.WebClient).DownloadString("http://169.254.169.254/latest/meta-data/instance-id")
Add-EC2Volume -VolumeId $volumeid -InstanceId $instanceId -Device xvdf -Region us-east-1