Skip to content

Advice on Route53 Subdomain Delegation Automation

0

I have a hosted domain (e.g., example.com) that was set up in the root account of my AWS organization structure. This Route53 hosted domain was setup a long time ago before my organization setup multiple accounts and started using Organizations. I have OUs with other accounts under that root account that serve web applications (e.g., app1.example.com). I seek advice on best practices on automating this setup in such a way that if I create a new application in a dev account OU that creates a new webapp with a url devapp2.example.com, that this subdomain gets properly registered, and if this application gets removed (destroyed) that this subdomain gets properly de-regisitered.

I have read about Routing Traffic for Subdomains, and I understand the basic concepts. However, I am trying to figure a set of best practices and/or advice on properly automating this process. The ultimate goal is to allow my devs to be able to spin up a webapp and test it in their AWS account, and then tear it down when they are done testing without having to go into the root account and manually registering a subdomain everytime.

The webapps are built using CDK and are hosted in GitHub and deployed using GitHub Actions.

2 Answers
1

To automate the process of subdomain delegation for your Route 53 setup across multiple AWS accounts, you can implement the following best practices:

  1. Use AWS Organizations and Service Control Policies (SCPs) to manage permissions across accounts, ensuring that only authorized accounts can make changes to DNS records.

  2. Implement a centralized DNS management system in your root account. This could be a custom application or Lambda function that handles subdomain creation and deletion requests from other accounts.

  3. Utilize AWS Step Functions or AWS Lambda to create a workflow that automates the process of subdomain creation and deletion. This workflow should include:

    • Creating a hosted zone for the subdomain in the target account
    • Adding necessary DNS records to the new hosted zone
    • Updating the parent domain's NS records in the root account to delegate the subdomain
  4. Use AWS CloudFormation or AWS CDK to define and manage the infrastructure for your subdomains. This ensures consistency and makes it easier to tear down resources when they're no longer needed.

  5. Implement a notification system (e.g., using Amazon SNS) to alert administrators of subdomain changes for auditing purposes.

  6. For your GitHub Actions workflow:

    • Create a custom action or script that communicates with your centralized DNS management system to request subdomain creation or deletion.
    • Include this action in your CI/CD pipeline, triggering it during deployment and teardown processes.
  7. Implement proper error handling and rollback mechanisms in case of failures during the subdomain delegation process.

  8. Use AWS Identity and Access Management (IAM) roles with the principle of least privilege to grant necessary permissions for subdomain management across accounts.

  9. Regularly audit and monitor your DNS configurations using AWS Config rules or custom scripts to ensure compliance and detect any unauthorized changes.

  10. Consider using Route 53 Traffic Flow for more advanced routing configurations if your applications require it.

By implementing these practices, you can create a robust, automated system for managing subdomains across your AWS organization. This will allow your developers to easily spin up and tear down web applications with proper subdomain registration and de-registration, without needing manual intervention in the root account.
Sources
Best practices for Amazon Route 53 DNS - Amazon Route 53
Using Amazon Route 53 as the DNS service for subdomains without migrating the parent domain - Amazon Route 53
Creating a subdomain that uses Amazon Route 53 as the DNS service without migrating the parent domain - Amazon Route 53
Best practices for Amazon Route 53 - Amazon Route 53

answered 2 years ago

EXPERT

reviewed 2 years ago

1

Here's concise solution for automating subdomain management.

  1. You mentioned that you have Root Account Setup
  • Keep the main hosted zone (example.com)
  • Create an IAM role with limited Route53 permissions
  • Enable cross-account access for your Child accounts
  1. CDK Implementation: ** This is where you would need to have class definition with Root Zone lookup and DNS record creation ** Doc : https://docs.aws.amazon.com/cdk/
  • Class Definition:
  • Assume role in Root account
  • Root Zone Lookup:
  • Sub-domain DNS Record Creation: <<<< this should also have removal policy once CF stack is destroyed
  1. GitHub Actions Workflow: Doc: https://docs.github.com/en/actions

Please let us know if this helps.

AWS

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.