LoginSignup
1

More than 5 years have passed since last update.

AWS CLIとjqコマンドを使ってHostedZoneNameから登録されているFQDNを検索する方法

Last updated at Posted at 2016-06-30
 % aws route53 list-resource-record-sets --hosted-zone-id `aws route53 list-hosted-zones-by-name --dns-name example.com. --max-items 1 | jq -r '.HostedZones[] | .Id' | cut -f 3 -d '/'` | jq -r '.ResourceRecordSets[].Name' | grep aws-in | grep momokuri | sed 's/.$//'
momokuri-dev-admin.aws-in.example.com
momokuri-dev-admin01.aws-in.example.com
momokuri-dev-admin02.aws-in.example.com
momokuri-dev-api.aws-in.example.com
momokuri-dev-api01.aws-in.example.com
momokuri-dev-api02.aws-in.example.com
momokuri-dev-db-arbiter.aws-in.example.com
momokuri-dev-db-primary.aws-in.example.com
momokuri-dev-db-secondary.aws-in.example.com
momokuri-dev-factory01.aws-in.example.com
momokuri-dev-search.aws-in.example.com
momokuri-dev-search01.aws-in.example.com
momokuri-dev-search02.aws-in.example.com
momokuri-dev-search03.aws-in.example.com

さすがに長過ぎて見づらいので、変数に一度割り当てるとこんな感じ。

 % HOSTED_ZONE_ID=$(aws route53 list-hosted-zones-by-name --dns-name example.com. --max-items 1 | jq -r '.HostedZones[] | .Id' | cut -f 3 -d '/')
 % aws route53 list-resource-record-sets --hosted-zone-id $HOSTED_ZONE_ID | jq -r '.ResourceRecordSets[].Name' | grep aws-in | grep momokuri | sed 's/.$//'

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1