Help us understand the problem. What is going on with this article?

Route53に登録されたレコードを全取得するスクリプト

More than 1 year has passed since last update.

実行条件

  • awscliをインストールしておく
  • EC2インスタンスにアクセスキー ID とシークレットアクセスキーを登録する
#route53.py

import commands
import json

MKDIR=commands.getoutput("mkdir RECORD")
HostZone = commands.getoutput("aws route53 list-hosted-zones")

HostZoneJson = json.loads(HostZone)

for h in HostZoneJson["HostedZones"]:
  HostZoneId = h['Id']
  HostZoneName = h['Name']
  File = "RECORD/" + HostZoneName + "txt"
  f = open(File, 'w')

  AwsCli = "aws route53 list-resource-record-sets --hosted-zone-id " +  HostZoneId 
  Record = commands.getoutput(AwsCli)
  RecordJson = json.loads(Record)

  for r in RecordJson['ResourceRecordSets']:
    Name = r.get('Name')
    Type = r.get('Type')
    TTL = r.get('TTL')
    Resouce = r.get('ResourceRecords')
    Alias = r.get('AliasTarget')

    if Alias != None:
      DNSName = Alias.get('DNSName')
      OutPut = Name + "," + Type + "," + "Alias " + DNSName + "," + "60" + "\n"
      f.write(OutPut)  
    else:
      Value = ""

      for v in Resouce:
        Value = Value + " " + v.get('Value') 

      OutPut = Name + "," + Type + "," +  Value + "," + str(TTL) + "\n"
      f.write(OutPut)

実行方法

python route53.py

ホストゾーン毎にファイルが作成され、レコード一覧が各ファイルに記載される

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした