2022-11-14 09:41:12 +08:00
|
|
|
#!/bin/bash
|
2023-07-04 08:16:09 +08:00
|
|
|
# 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
|
2022-11-14 09:41:12 +08:00
|
|
|
|
2024-01-13 00:25:30 +08:00
|
|
|
#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...
|
2022-11-14 09:41:12 +08:00
|
|
|
aws cloudwatch list-metrics --namespace CWAgent --metric-name disk_inodes_free \
|
2024-01-13 00:25:30 +08:00
|
|
|
--dimensions Name=InstanceId,Value=$iid Name=path,Value=/ --query Metrics[] | \
|
|
|
|
jq '. | last | .Dimensions[] | {(.Name):(.Value)}' | jq -s 'add'
|