LoginSignup
13
15

More than 5 years have passed since last update.

AWS CLIを使ってRoute53に登録されている情報を調べる

Last updated at Posted at 2016-02-16

Route53に登録されている情報を調べる
AWSCLI使っているけどjqの使い方がメインの話

HostedZonesを調べる

aws route53 list-hosted-zones --profile PROFILENAME

json形式でRoute53へ登録されているHostedZones情報が見れる
jqコマンド等で適宜必要な情報を取得する

HostedZoneIDを調べる

aws route53 list-hosted-zones --profile PROFILENAME | jq -c -r '.HostedZones[].Id'

/hostedzone/xxxxxxxxxxの形式で出力する。見づらい場合は jq -c -r '.HostedZones[]|[.Name,.Id]'なりで出力
このIDを利用して色々チェックする

HostedZoneに設定されている一覧を見る

aws route53 list-resource-record-sets --hosted-zone-id /hostedzone/xxxxxxxx --profile PROFILE

json形式でHostedZoneに登録されている情報が見れる
先ほどと同じようにjqコマンド等で必要な情報を取得

特定のTypeのレコードを出力する

登録されているレコード一覧の作成

aws route53 list-resource-record-sets --hosted-zone-id /hostedzone/xxxxxxxx --profile PROFILENAME | jq -c -r '.ResourceRecordSets[].Name'

この状態だとAレコードだけでなくNSやTXT、SOA等も全て出力してしまう。
なので特定のレコードだけを出力する

aws route53 list-resource-record-sets --hosted-zone-id /hostedzone/xxxxxxxx --profile PROFILENAME | jq -c -r '.ResourceRecordSets[]| if .Type == "A" then .Name else empty end'

これでAレコードだけの出力が出来る。
複数のレコードを条件としたい場合は elif で繋いで出力する

aws route53 list-resource-record-sets --hosted-zone-id /hostedzone/xxxxxxxx --profile PROFILENAME | jq -c -r '.ResourceRecordSets[]| if .Type == "A" then [.Type,.Name] elif .Type == "CNAME" then [.Type,.Name] else empty end'

AWS CLIのCommandReferenceはこちらroute53

13
15
0

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
13
15