LoginSignup
10
5

More than 5 years have passed since last update.

AWS CLIを使ってRoute53の操作

Last updated at Posted at 2018-05-10

概要

GUIからCUIに移行しているので使いそうなコマンドをメモとして残しておきます。
コード化したり自動化できたりするので便利ですね。

環境

$ aws --version
aws-cli/1.14.30 Python/3.6.4 Darwin/16.7.0 botocore/1.8.34

$ jq --version
jq-1.5

Zoneの作成

$ aws route53 create-hosted-zone --name example.com --caller-reference `date +%Y-%m-%d_%H-%M-%S`

Zoneの一覧確認

$ aws route53 list-hosted-zones | jq '.HostedZones[] | {Id, Name}'

レコード一覧の確認

$ aws route53 list-resource-record-sets --hosted-zone-id /hostedzone/xxxxx | jq '.ResourceRecordSets'

Aレコードの登録・更新・削除

これについてはjsonを使わないとダメっぽい。「--generate-cli-skeleton」でテンプレートを作ってjsonを読み込むようにしましょう。

$ aws route53 change-resource-record-sets --hosted-zone-id /hostedzone/xxxxx --change-batch file://test.json
{
  "Changes": [
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "www.example.com.",
        "Type": "A",
        "TTL": 300,
        "ResourceRecords": [
          {
            "Value": "xxx.xxx.xxx.xxx"
          }
        ]
      }
    },
    {
      "Action": "UPSERT",
      "ResourceRecordSet": {
        "Name": "www.example.com.",
        "Type": "A",
        "TTL": 300,
        "ResourceRecords": [
          {
            "Value": "xxx.xxx.xxx.xxx"
          }
        ]
      }
    },
    {
      "Action": "DELETE",
      "ResourceRecordSet": {
        "Name": "www.example.com.",
        "Type": "A",
        "TTL": 300,
        "ResourceRecords": [
          {
            "Value": "xxx.xxx.xxx.xxx"
          }
        ]
      }
    }
  ]
}
10
5
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
10
5