#!/bin/bash # Get the query TERRAFORM_QUERY=$(jq -Mc .) # Extract the query attributes access_key=$(echo "${TERRAFORM_QUERY}" | jq -r '.access_key') secret_key=$(echo "${TERRAFORM_QUERY}" | jq -r '.secret_key') session_token=$(echo "${TERRAFORM_QUERY}" | jq -r '.session_token') iid=$(echo "${TERRAFORM_QUERY}" | jq -r '.iid') # eval "$(jq -r '@sh "export id=\(.input) asrolearn=\(.asrolearn)"')" # eval $(aws sts assume-role --role-arn $asrolearn --role-session-name awscli | jq -cr '"export AWS_ACCESS_KEY_ID=" + .Credentials.AccessKeyId, "export AWS_SECRET_ACCESS_KEY=" + .Credentials.SecretAccessKey, "export AWS_SESSION_TOKEN=" + .Credentials.SessionToken, "export AWS_SESSION_EXPIRATION=" + .Credentials.Expiration') export AWS_ACCESS_KEY_ID=$access_key export AWS_SECRET_ACCESS_KEY=$secret_key export AWS_SESSION_TOKEN=$session_token #aws cloudwatch list-metrics --namespace CWAgent --metric-name disk_inodes_free \ #--dimensions Name=InstanceId,Value=$iid Name=path,Value=/ | \ #jq '.Metrics[] | .Dimensions[] | {(.Name):(.Value)}' | jq -s 'add' # when there are multiple metrics with the same name... aws cloudwatch list-metrics --namespace CWAgent --metric-name disk_inodes_free \ --dimensions Name=InstanceId,Value=$iid Name=path,Value=/ --query Metrics[] | \ jq '. | last | .Dimensions[] | {(.Name):(.Value)}' | jq -s 'add'