Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dkershner6/cdk-cloudfront-associate-alias
A simple construct to handle automated Cloudfront DNS alias migration with zero downtime
https://github.com/dkershner6/cdk-cloudfront-associate-alias
Last synced: 29 days ago
JSON representation
A simple construct to handle automated Cloudfront DNS alias migration with zero downtime
- Host: GitHub
- URL: https://github.com/dkershner6/cdk-cloudfront-associate-alias
- Owner: dkershner6
- License: apache-2.0
- Created: 2023-11-02T16:17:34.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-07T02:03:43.000Z (11 months ago)
- Last Synced: 2024-09-29T05:46:45.215Z (about 2 months ago)
- Language: TypeScript
- Size: 326 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cdk-cloudfront-associate-alias
A simple construct to handle automated Cloudfront DNS alias migration with zero downtime.
[NPM Package](https://www.npmjs.com/package/cdk-cloudfront-associate-alias)
[![View on Construct Hub](https://constructs.dev/badge?package=cdk-cloudfront-associate-alias)](https://constructs.dev/packages/cdk-cloudfront-associate-alias)
## Usage
Usage of this construct is fairly straightforward. Simply pass in the Cloudfront distribution, the Route53 hosted zone, and the alias you want to associate with the distribution.
```typescript
const customDomain = "example.com";
const hostedZone = route53.HostedZone.fromLookup(this, "HostedZone", {
domainName: DOMAIN_NAME,
});
const targetDistribution =
cloudfront.Distribution.fromDistributionAttributes(
this,
"Distribution",
{
distributionId,
domainName: distributionDomainName,
},
);new CloudfrontAliasAssociator(
this,
"AliasAssociator",
{
alias: customDomain,
hostedZone,
targetDistribution,
},
);
```## What this does
This construct will create:
1. A TXT record, this is specific to the API call used, and ensures you have ownership of the domain.
2. A Custom Resource that makes an `AssociateAlias` API call to Cloudfront. This API specifically is for zero downtime alias migration in Cloudfront. This will work even if the domain isn't pre-associated.
3. An A and AAAA alias record that points to the (new) Cloudfront distribution.## Use Cases
Notably, this construct can be used to provide Blue/Green style deployments for Cloudfront distributions. This means you can create a new distribution, associate the alias with it and this will result in zero downtime for your users.
You can also use this construct in reverse to rollback your alias to the previous deployment (or any other deployment).
For this use case, I recommend pairing this construct with the [cdk-versioned-stack-manager](https://constructs.dev/packages/cdk-versioned-stack-manager) to manage your versioned stacks.