I'm trying to parse the output of AWS cli using jq where the jq query contains bash variables and by using the --arg switch like so:
$ aws ec2 describe-instances --region $region | jq --arg environment "$Environment" --arg br "$BUILD_NUMBER" --arg app "$App" -r '.Reservations[].Instances[].Tags[]?.Value | select(startswith("Company-$environment-$br-$app")
I get a new line when I run the command.
This is the output when I use hard coded auto scaling group name:
itai@Itais-MBP ~/Downloads - $ aws ec2 describe-instances --region $region | jq --arg environment "$Environment" --arg br "$BUILD_NUMBER" --arg app "$App" -r '.Reservations[].Instances[].Tags[]?.Value | select(startswith("Company-Dev-60-Api") )'
Company-Dev-60-ApiServersASG-19L10K16RUXTE
Company-Dev-60-ApiServersASG-19L10K16RUXTE
itai@Itais-MBP ~/Downloads - $
You can see the values of the variables are set:
itai@Itais-MBP ~/Downloads - $ echo $Environment
Dev
itai@Itais-MBP ~/Downloads - $ echo $App
Api
itai@Itais-MBP ~/Downloads - $ echo $BUILD_NUMBER
60
So what am I doing wrong?