CDK Construct to simplify using CloudFront to redirect entire domains or back-half stubs
npm install cdk-cloudfront-redirectorCDK Construct to simplify using CloudFront to redirect entire domains or back-half stubs. Published as cdk-cloudfront-redirector (NPM)
!GitHub Release !NPM Downloads
Needs to redirect domains or building custom link shorteners is a common pattern required by many different solutions. This project simplifies using Amazon CloudFront with CloudFront Functions to rewrite the requests, forwarding users to another location.
!CloudFront Redirector Construct Diagram
This construct is able to either perform redirections for everything sent to a domain, or based on the back-half of the URL.
You might use this for something as simple as redirecting an unused www subdomain to a root apex, or for building your own link shortener service, similar to bit.ly.
For more details, check the auto-generated API.
``bash`CDK for Typescript
npm install cdk-cloudfront-redirector
`typescript
import { RedirectionSite } from 'cdk-cloudfront-redirector';
// Basic Setup
const redirectBasic = new RedirectionSite(this, "RedirectionForWebsite", {
targetUrl: "https://ssennett.net/",
});
// Advanced Setup
const redirectAdvanced = new RedirectionSite(this, "RedirectionForWebsite", {
targetUrl: "https://github.com/ssennettau/CloudFrontRedirector-Construct",
pathRedirects: [
path: "/author",
destination: "https://ssennett.net/",
],
customDomain: {
domainName: "cfrc.cc",
hostedZone: "cfrc.cc",
}
});
// Return outputs
new cdk.CfnOutput(this, "RedirectionUrl", { value: redirectAdvanced.cfDistributionUrl });
``
All code in this project is licensed under the MIT License.