How to set Alternative Domain Name (CName) in aws-cloudfront
See original GitHub issueI can’t seem to find how to set the alternative domain name in cloudfront. I looked through the source code but couldn’t find any. Here is my code
import * as cloudfront from '@aws-cdk/aws-cloudfront';
// import * as route53 from '@aws-cdk/aws-route53';
import * as s3 from '@aws-cdk/aws-s3';
import * as cdk from '@aws-cdk/cdk';
import { ViewerProtocolPolicy } from '@aws-cdk/aws-cloudfront';
export interface StaticSiteProps {
domainName: string;
siteSubDomain: string;
certificateArn?: string;
s3Region: string;
}
export class StaticSite extends cdk.Construct {
constructor(parent: cdk.Construct, name: string, props: StaticSiteProps) {
super(parent, name);
const siteDomain = props.siteSubDomain + '.' + props.domainName;
const siteBucket = new s3.Bucket(this, 'SiteBucketReal', {
bucketName: siteDomain,
websiteIndexDocument: 'index.html',
websiteErrorDocument: 'index.html',
publicReadAccess: true,
});
new cdk.Output(this, 'SiteBucketName', { value: siteBucket.bucketName });
const distribution = new cloudfront.CloudFrontWebDistribution(
this,
'SiteDistribution',
{
// TODO: Set Alternative Domain Name?
viewerProtocolPolicy: ViewerProtocolPolicy.AllowAll,
originConfigs: [
{
customOriginSource: {
domainName: `${siteDomain}.s3-website-${
props.s3Region
}.amazonaws.com`,
},
behaviors: [{ isDefaultBehavior: true }],
},
],
},
);
new cdk.Output(this, 'DistributionId', {
value: distribution.distributionId,
});
}
}
I’m trying to translate this https://aws.amazon.com/premiumsupport/knowledge-center/cloudfront-serve-static-website/ to aws-cdk
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Using custom URLs by adding alternate domain names ...
In CloudFront, an alternate domain name, also known as a CNAME, lets you use your own domain name (for example, www.example.com) in your...
Read more >Amazon CloudFront Alternate Domain Names
And only then update your distribution to add an alternate domain name: Open Amazon CloudFront console -> General view -> Edit -> Alternate...
Read more >Configuring alternate domain names and HTTPS
To use alternate domain names in the URLs for your files and to use HTTPS between viewers and CloudFront, perform the applicable procedures....
Read more >Set up Your Domain with CloudFront
Head over to the details of your CloudFront Distribution and hit Edit. ... And type in your new domain name in the Alternate...
Read more >How to Setup Custom Domain for Amazon CloudFront?
Now, you can click on “Edit” and then add the custom domain to the “Alternate Domain Names” option. The alternate domain CloudFront is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For us, the easiest way to achieve CNAME aliases + custom certificate was to use the
viewerCertificate
option in thecloudfront.CloudFrontWebDistribution
constructor:VS Code marks
aliasConfiguration
as deprecated, which is why we use the above instead. There’s also additionalprops
options: https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudfront.CfnDistribution.ViewerCertificateProperty.htmlas of
1.91.0
-With
new cloudfront.Distribution
TLSv1.2_2019
which is niceWith
new cloudfront.CloudFrontWebDistribution
TLSv1
which is badare there plans to improve the
Distribution
API?