Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-route53-targets: Add Global Accelerator target for Route53 alias #12839

Assignees
Labels
@aws-cdk/aws-route53-targets effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@luketn
Copy link
Contributor

luketn commented Feb 3, 2021

Add a new Route53 alias target implementation for Global Accelerator.

Use Case

You can create a Global Accelerator with CDK as documented here:
https://docs.aws.amazon.com/cdk/api/latest/docs/aws-globalaccelerator-readme.html

However when you try to create a Route53 alias to the Global Accelerator as discussed here:
"To use your custom domain name with Global Accelerator when you use Route 53 as your DNS service, you create an alias record that points your custom domain name to the DNS name assigned to your accelerator. An alias record is a Route 53 extension to DNS."
https://docs.aws.amazon.com/global-accelerator/latest/dg/dns-addressing-custom-domains.mapping-your-custom-domain.html

There is CloudFormation support for it as discussed here:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-aliastarget-1.html

But no CDK support.

Proposed Solution

Add a new CDK alias target class 'GlobalAcceleratorTarget', which simplifies creating an alias target to a Global Accelerator.

The Hosted Zone should be set as per the documentation here:
"Amazon Route 53 Hosted Zone ID: Z2BJ6XQ5FK7U4H"
https://docs.aws.amazon.com/general/latest/gr/global_accelerator.html

The Global Accelerator could be passed in the constructor, either as an object or a string (the DNS).

Working implementation:

import {IRecordSet, IAliasRecordTarget, AliasRecordTargetConfig} from "@aws-cdk/aws-route53";
import {IAccelerator} from "@aws-cdk/aws-globalaccelerator";

export class GlobalAcceleratorTarget implements IAliasRecordTarget {
    /**
     * The hosted zone Id if using an alias record in Route53.
     * This value never changes.
     * Ref: https://docs.aws.amazon.com/general/latest/gr/global_accelerator.html
     */
    public static readonly GLOBAL_ACCELERATOR_ZONE_ID = 'Z2BJ6XQ5FK7U4H';

    /**
     * Create an Alias Target for a Global Accelerator.
     *
     * If passing a string value, it must be a valid DNS name for an existing Global Accelerator. e.g. xyz.awsglobalaccelerator.com
     * If passing an instance of an accelerator created within CDK, the accelerator.dnsName property will be used as the target.
     */
    constructor(private readonly accelerator: string | IAccelerator) {
    }

    bind(record: IRecordSet): AliasRecordTargetConfig {
        let acceleratorDomainName;
        if (typeof this.accelerator === "string") {
            acceleratorDomainName = this.accelerator;
        } else {
            acceleratorDomainName = this.accelerator.dnsName;
        }
        return {
            hostedZoneId: GlobalAcceleratorTarget.GLOBAL_ACCELERATOR_ZONE_ID,
            dnsName: acceleratorDomainName
        };
    }
}

This is a 🚀 Feature Request

@luketn luketn added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Feb 3, 2021
@njlynch
Copy link
Contributor

njlynch commented Mar 3, 2021

Thanks for the feature request and implementation! Can you submit a PR for this, and add some tests? Would be happy to work with you to get this incorporated into the CDK.

@njlynch njlynch added effort/medium Medium work item – several days of effort p2 and removed needs-triage This issue or PR still needs to be triaged. labels Mar 3, 2021
@luketn
Copy link
Contributor Author

luketn commented Mar 4, 2021

Thanks for the feature request and implementation! Can you submit a PR for this, and add some tests? Would be happy to work with you to get this incorporated into the CDK.

Awesome, will do!

@luketn
Copy link
Contributor Author

luketn commented Mar 5, 2021

Hi @njlynch - I've added a PR - #13407 for the new feature adding a Route53 alias target for Global Accelerator.

It has unit tests and integration tests, and I've run the integration test script against my personal AWS account to prove it deploys as expected.

I have added a README section to the module in line with the other examples:
image

Let me know if there are any issues and I'll take a look.

@mergify mergify bot closed this as completed in #13407 Mar 5, 2021
mergify bot pushed a commit that referenced this issue Mar 5, 2021
…lias targets (#13407)

Closes #12839 
----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Mar 5, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

This was referenced Mar 6, 2021
cornerwings pushed a commit to cornerwings/aws-cdk that referenced this issue Mar 8, 2021
…lias targets (aws#13407)

Closes aws#12839 
----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment