How do I create a simple resource record set in Amazon Route 53 using the AWS CLI?

Lesedauer: 3 Minute
0

How can I create a simple resource record set in Amazon Route 53 using the AWS Command Line Interface (AWS CLI)?

Short description

You can create, delete, or change (upsert) a resource record set using a ChangeResourceRecordSets request to the Route 53 API.

Resolution

Note: If you receive errors when running AWS CLI commands, make sure that you’re using the most recent AWS CLI version.

Create a ChangeResourceRecordSets request

You can perform the following actions using a ChangeResourceRecordSets request:

  • CREATE creates a record set with a specified value in the hosted zone
  • DELETE deletes a record set with a specified value in the hosted zone
  • UPSERT either creates a new record set with a specified value, or updates a record set with a specified value if that record set already exists

Modify the following example JSON file (sample.json) to create, delete, or change a simple A record set. The request’s body includes a list of change items, known as a change batch:

{
            "Comment": "CREATE/DELETE/UPSERT a record ",
            "Changes": [{
            "Action": "CREATE",
                        "ResourceRecordSet": {
                                    "Name": "a.example.com",
                                    "Type": "A",
                                    "TTL": 300,
                                 "ResourceRecords": [{ "Value": "4.4.4.4"}]
}}]
}

Create a resource record set for your domain in the hosted zone using the Route 53 API with the command change-resource-record-sets. The sample.json file specifies the values for record creation.

$ aws route53 change-resource-record-sets --hosted-zone-id ZXXXXXXXXXX --change-batch file://sample.json

A Status of PENDING should be returned with the unique ID, unless there's an error in the JSON file:

$ aws route53 change-resource-record-sets --hosted-zone-id ZXXXXXXXXXXX --change-batch file://sample.json
{
    "ChangeInfo": {
        "Status": "PENDING", 
        "Comment": "optional comment about the changes in this change batch request", 
        "SubmittedAt": "2018-07-10T19:39:37.757Z", 
        "Id": "/change/C3QYC83OA0KX5K"
    }
}

Use the API call get-change with the Id value from your change-resource-record-sets response to check the status of the changes:

  • PENDING indicates that the changes in this request aren't yet propagated to all Route 53 DNS servers. This is the initial status of all change batch requests.
  • INSYNC indicates that the changes are propagated to all Route 53 DNS servers.

Before propagation:

aws route53  get-change --id /change/C3QYC83OA0KX5K
{
    "ChangeInfo": {
        "Status": "PENDING", 
        "Comment": "optional comment about the changes in this change batch request", 
        "SubmittedAt": "2018-07-10T19:39:37.757Z", 
        "Id": "/change/C3QYC83OA0KX5K"
    }
}

After propagation:

$ aws route53  get-change --id /change/C3QYC83OA0KX5K
{
    "ChangeInfo": {
        "Status": "INSYNC", 
        "Comment": "optional comment about the changes in this change batch request", 
        "SubmittedAt": "2018-07-10T19:39:37.757Z", 
        "Id": "/change/C3QYC83OA0KX5K"
    }

Create concurrent requests

You must use separate Action keys for each concurrent request. For example, you can't create an A record and an MX record in one request. Instead, you must create two record sets for the same domain name using the following format:

{
                "Comment": "CREATE/DELETE/UPDATE",
                 "Changes": [ {
                             "Action": "CREATE",
                            "ResourceRecordSet": {
                                "Name": "a.example.com",
                                    "Type": "A",
                                     "TTL": 300,
                                  "ResourceRecords": [{"Value": "5.5.5.5"}]
                            }},
{
                            "Action": "CREATE",
                            "ResourceRecordSet": {
                                 "Name": "a.example.com",
                                 "Type": "MX",
                                  "TTL": 300,
                                  "ResourceRecords": [{"Value": "10 example.com"}]
                           }}
]
}

Related information

How do I troubleshoot errors with creating Amazon Route 53 resource record sets using the AWS CLI?

AWS OFFICIAL
AWS OFFICIALAktualisiert vor 2 Jahren
Keine Kommentare