- Newest
- Most votes
- Most comments
You won't be able to add it in (easily) with CDK. Because you are looking it up from attributes, when it synths the template, there won't be a CloudFront distribution in the resource section of the template.
You would have to create a stack with CDK that contains a distribution. Synth the template for that stack. Then create the stack manually using the template and import the CloudFront Distribution into the stack.
This would then allow you to interact with the Distribution via CDK.
The easier alternative would be to use a Custom Resource to use the Update Distribution API to add these values.
Unfortunately it is not possible to modify an imported existing distribution - you would need to create a new distribution
Existing distributions can be imported as well; note that like most imported constructs, an imported distribution cannot be modified. However, it can be used as a reference for other higher-level constructs
https://docs.aws.amazon.com/cdk/api/latest/docs/aws-cloudfront-readme.html
You could theoretically create a CustomResource that would called a Lambda function to update the distribution via an API call, if you really needed to have this functionality bundled into your CDK stack
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 files’ URLs instead of using the domain name that CloudFront assigns to your distribution. When you create a distribution, CloudFront provides a domain name for the distribution, such as d111111abcdef8.cloudfront.net. If you want to use your own domain name, such as www.example.com, instead of the cloudfront.net domain name, you can add an alternate domain name to your distribution.
You can use the domainNames? parameter
Type: string[] (optional, default: The distribution will only support the default generated name (e.g., d111111abcdef8.cloudfront.net)) Alternative domain names for this distribution.
If you want to use your own domain name, such as www.example.com, instead of the cloudfront.net domain name, you can add an alternate domain name to your distribution. If you attach a certificate to the distribution, you must add (at least one of) the domain names of the certificate to this list.
With the AWS CLI you would call
aws cloudfront associate-alias --alias www.example.com --target-distribution-id EDFDVBD6EXAMPLE
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/CNAMEs.html
Hi, I believe that's not possible at the moment. The documentation states
Existing distributions can be imported as well; note that like most imported constructs, an imported distribution cannot be modified. However, it can be used as a reference for other higher-level constructs.
Relevant content
- asked 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated 3 years ago
Creating Custom Resource to use the Update Distribution API is actually a great idea! Thanks!