AWSでプロジェクトに存在するALBを一覧する

Jan 20, 2019 14:57 · 107 words · 1 minute read

aws cloudwatch list-metrics \
    --namespace AWS/ApplicationELB \
    --metric-name RequestCount \
    | jq -r '.Metrics[].Dimensions[] | select(.Name | test("LoadBalancer")) | .Value' \
    | sort \
    | uniq

jq の部分はjsonから必要な部分を抜き出すためのもの

  • 配列を Name=LoadBalancer なオブジェクトにフィルタして
  • そのオブジェクトの Value 属性を取り出す
[
    {
        "Name": "TargetGroup",
        "Value": "targetgroup/stg-api/xxxxxx"
    },
    {
        "Name": "LoadBalancer",
        "Value": "app/stg-private/ggggggg"
    },
    {
        "Name": "AvailabilityZone",
        "Value": "ap-northeast-1c"
    }
]
tweet Share