Skip to content

How do I get notifications when changes happen to my Route 53 hosted zone records?

4 minute read
0

I want to receive an email response with a custom notification when I create or delete resource record sets from Amazon Route 53.

Short description

Use a custom event pattern with an Amazon EventBridge rule or Amazon CloudWatch Events rule that initiates when you make the ChangeResourceRecordSets API call. Then, route the response to an Amazon Simple Notification Service (Amazon SNS) topic.

Note: If you don't have an Amazon SNS topic with an email subscription, then create an Amazon SNS topic and a subscription to an SNS topic.

Resolution

Prerequisite: To monitor AWS API Call via CloudTrail events, activate custom CloudTrail trails in the AWS Regions where you create the rules. To record events with one of the CloudTrail detail-type values, you must turn on logging for a trail. You can create a trail either in multiple Regions or in only the us-east-1 Region. For more information, see Working with CloudTrail trails.

Create an EventBridge rule

Note: Route 53 is an AWS global service that's available only in the US East (N. Virginia) AWS Region. You must create the EventBridge rule in the US East (N. Virginia) Region.

Complete the following steps:

  1. Open the EventBridge console.

  2. In the navigation pane, choose Rules.

  3. Choose Create rule.

  4. In the Name and Description fields, enter a name and description for the rule.

  5. Select Enable the rule on the selected eventbus.

  6. Choose Rule with an event pattern.

  7. Choose Next.

  8. Select AWS Events or EventBridge partner events.

  9. Under Event pattern, choose the following options:
    In the Event source dropdown list, choose AWS services.
    In the AWS service dropdown list, choose Route 53.
    In the Event type dropdown list, choose AWS API Call via CloudTrail.

  10. Choose Specific operation(s).

  11. In Specific operation(s), enter ChangeResourceRecordSets to limit events to match only for create, delete, or updates to resource record sets.
    The following event pattern appears:

    {  
      "source": ["aws.route53"],  
      "detail-type": ["AWS API Call via CloudTrail"],  
      "detail": {  
        "eventSource": ["route53.amazonaws.com"],  
        "eventName": ["ChangeResourceRecordSets"]  
      }  
    }
  12. Choose Next.

Associate the Amazon SNS target with the EventBridge rule

Complete the following steps:

  1. Open the EventBridge console.
  2. In the Target types section, select AWS service.
  3. In the Select a target dropdown list, choose SNS topic.
  4. In the Topic dropdown list, choose your Amazon SNS topic.

Configure the Input transformer option to customize the SNS notification

By default, EventBridge forwards the entire CloudTrail event to the target. Then, the Amazon SNS topic delivers a notification as unformatted JSON text.

When you use the Input transformer option on the EventBridge console, you can specify the fields in the inbound event. Then, the Input transformer transforms the event into a more human-readable message. 

In the following steps, the example Input path field includes the eventTime, hostedZone, username, and eventID. Change the fields to align with your use case. EventBridge automatically updates the field placeholders in the Input template with the fields that you configure in the Input transformer.

To customize an Amazon SNS notification, complete the following steps:

  1. Open the EventBridge console.

  2. Expand the Additional settings dropdown list.

  3. In the Configure target input dropdown list, choose Input transformer.

  4. Choose Configure Input transformer.

  5. In the Input path field, enter the following code:

    {  
        "eventTime": "$.detail.eventTime",  
        "hostedZone": "$.detail.requestParameters.hostedZoneId",  
        "userName": "$.detail.userIdentity.sessionContext.sessionIssuer.userName",  
        "eventID": "$.detail.eventID"  
    }
  6. In the Template field, enter the following text:
    "At eventTime, one or more Route 53 records within Hosted Zone hostedZone were modified by user userName. To view the event directly in your Event History and review these changes, use the following link. Note that the event may take up to 15 minutes to be available in your Event History: https://console.aws.amazon.com/cloudtrail/home?region=us-east-1#/events?EventId=eventID"
    Note: Replace userName with your username.

  7. Choose Confirm.

  8. (Optional) Add tags to the EventBridge rule, and then choose Next.

  9. Review the rule configuration, and then choose Create rule.

When you change the Route 53 resource sets, you now get a notification that's similar to the following:

"At 2022-08-16T21:02:46Z, one or more Route 53 records within Hosted Zone ZB3A123456789 were modified by user Admin. To view the event directly in your Event History and review these changes, use the following link. Note that the event may take up to 15 minutes to be available in your Event History: https://console.aws.amazon.com/cloudtrail/home?region=us-east-1#/events?EventId=04d08662-537e-4424-97c2-8bc796943b75"

Related information

How do I create a custom event pattern for an EventBridge rule?

How do I create an EventBridge rule that uses the input transformer to make an Amazon SNS notification human readable?

Tutorial: Use input transformers to transform events in EventBridge

Tutorial: Create an EventBridge rule that reacts to AWS API calls via CloudTrail

5 Comments

So how do I test that this is all working right? I've done all these steps, I've confirmed that I can send a test SNS and get the email, but when I make a change (adding a TXT record) to one of multiple domains in Route53, I don't get any notifications. I do see the change in the CloudTrail event logs. So I'm missing something on terms of hooking this all up and testing it.

Do I need to setup some sort or access controls so that EventBridge can send to CloudTrail which then talks to SNS? I'm stumped on why this is not working when I've followed all the steps given in this guide.

replied 2 years ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

AWS
MODERATOR

replied 2 years ago

So do you need to add access rule(s) to the "event bus" before you do anything else? I'm specifically talking about the "default" event bus. But even when I create a new event bus and add something like this in the permissions tab:

{ "Version": "2012-10-17", "Statement": [{ "Sid": "AllowAllAccountsFromOrganizationToPutEvents", "Effect": "Allow", "Principal": "*", "Action": "events:PutEvents", "Resource": "arn:aws:events:us-east-1:<ARN>:event-bus/route53", "Condition": { "StringEquals": { "aws:PrincipalOrgID": "<ID>" } } }] }

It's still not sending me emails when I create/delete TXT records in one of my domains. It would be really nice to have some way to actually debug this stuff and know how to look for errors chaining all these services together into a coherent setup.

And should I have "schema discovery" started at all?

replied 2 years ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

AWS
MODERATOR

replied 2 years ago

Hello John, to allow AWS API Call via CloudTrail type events, we have to ensure that a custom trail is setup (in all regions where you want to track AWS API Call via CloudTrail type events). In this case, you can create a trail in us-east-1 region

You can check Step 1, https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-log-api-call.html

Also from https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-service-event-cloudtrail.html

To record events with one of the CloudTrail detail-type values, you must enable a CloudTrail trail with logging. For more information, see Working with CloudTrail trails in the AWS CloudTrail User Guide.

One the trail is created, you can try creating the TXT record and check if the rule is working.

AWS
SUPPORT ENGINEER

replied 2 years ago