0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Route53の全レコードをまとめてテキストファイルに出力するワンライナー

Posted at

必要になったので書きました。必要なものはAWS CLI v2jq v1.6とgawk1です。なおこの記事の焼き直しです。

コマンド

aws route53 list-hosted-zones | \
  jq '.HostedZones[] .Id' -r | \
  gawk -F"/" '{cmd="aws route53 list-resource-record-sets --hosted-zone-id " $3 " | jq \x27.ResourceRecordSets [] | if has(\"ResourceRecords\") then [.Name, .Type, .TTL, ([.ResourceRecords[] .Value] | join(\",\"))] else [.Name, .Type, -1, (.AliasTarget .DNSName)] end | @tsv\x27 -r >" $3 ".tsv" ; system(cmd)}'

出力結果

hosted zoneごとに1ファイルが出力されます。

example.com.    MX  3600    1 aspmx.l.google.com,5 alt1.aspmx.l.google.com,5 alt2.aspmx.l.google.com,10 aspmx2.googlemail.com,10 aspmx3.googlemail.com
example.com.    NS  172800  ns-1411.awsdns-99.org.,ns-999.awsdns-99.net.,ns-9999.awsdns-99.co.uk.,ns-999.awsdns-99.com.
dev1.example.com.   A   300 203.0.113.1
dev2.example.com.   A   -1  dualstack.alb-name-999999999.ap-northeast-1.elb.amazonaws.com.

Q&A

Q: もはやワンライナーとは言えないのでは? 3行なのでは?
A: はい

  1. awkやnawkでも動くかもしれませんが試していません

0
2
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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?