ListActiveEC2Regions

nicolaw 25th July 2023 at 2:15pm
AWS awscli CodeSnippets
aws ce get-cost-and-usage \
    --time-period "Start=$(printf "%(%Y-%m-%d)T" "$(($(date +%s)-(60*60*48)))"),End=$(date +%Y-%m-%d)" \
    --granularity MONTHLY \
    --metrics "UsageQuantity" \
    --group-by Type=DIMENSION,Key=REGION \
    --output json \
    --filter '{"And":[{"Dimensions":{"Key":"SERVICE","Values":["Amazon Elastic Compute Cloud - Compute"]}},{"Dimensions":{"Key":"RECORD_TYPE","Values":["Usage"]}},{"Not":{"Dimensions":{"Key":"INSTANCE_TYPE","Values":[""]}}}]}' \
    | jq -re '[.ResultsByTime[].Groups[].Keys|add]|unique[]|select(. != "global")'