[英]How to add domain alias to existing CloudFront distribution using AWS CDK
I just deployed a CloudFormation solutions from the AWS Solutions.我刚刚从 AWS 解决方案部署了 CloudFormation 解决方案。 The solutions included a new CloudFront distribution.
这些解决方案包括一个新的 CloudFront 发行版。 My challenge is that I want to add a custom domain
mysite.example.com
to the dxxxxxx.cloudfront.net
distribution.我的挑战是我想将自定义域
mysite.example.com
添加到dxxxxxx.cloudfront.net
发行版。 I already created an alias and certificate using Certificate Manager.我已经使用证书管理器创建了别名和证书。 My question is how do I add a new domain to the existing CloudFront.
我的问题是如何将新域添加到现有 CloudFront。
I understand that we can import an existing distribution using Distribution.fromDistributionAttributes .我知道我们可以使用Distribution.fromDistributionAttributes导入现有分布。
for example例如
const distribution = cloudfront.Distribution.fromDistributionAttributes(this, 'ImportedDist', {
domainName: 'd111111abcdef8.cloudfront.net',
distributionId: '012345ABCDEF',
});
Let's say I have the alias domain name and certificate ARN ready to use.假设我已经准备好使用别名域名和证书 ARN。
const domainName = 'mysite.example.com';
const certificateArn = 'arn:aws:acm:us-east-1: 123456789012:certificate/abcdefgh-1234-5678-9012-abcdefghujkl';
Where do I go from here?我在哪里 go 从这里?
Add your domain and certificate by updating your "AWS solutions" CDK app.通过更新您的“AWS 解决方案”CDK 应用程序来添加您的域和证书。 CDK apps are designed be modified and redeployed.
CDK 应用程序旨在修改和重新部署。
The Distribution construct accepts the certificate?:ICertificate
and domainNames?: string[]
as props to the constructor. Distribution 构造接受
certificate?:ICertificate
和domainNames?: string[]
作为构造函数的 props。 Instances also expose a addBehavior(pathPattern, origin, behaviorOptions?)
, which seems handy.实例还公开了一个
addBehavior(pathPattern, origin, behaviorOptions?)
,这看起来很方便。
If the app is in production, be mindful that updates sometimes result in resource replacement or interruption .如果应用程序正在生产中,请注意更新有时会导致资源更换或中断。 The CloudFormation docs note the update behaviour for each service property.
CloudFormation 文档记录了每个服务属性的更新行为。 In the happy case you will see
Update requires: No interruption
.在快乐的情况下,您将看到
Update requires: No interruption
。 Run the cdk diff
command to preview the changes CloudFormation will make to your resources.运行
cdk diff
命令以预览 CloudFormation 将对您的资源所做的更改。
What about cloudfront.Distribution.fromDistributionAttributes
? cloudfront.Distribution.fromDistributionAttributes
怎么样? Many CDK classes have static from...
methods to get a reference to an existing AWS resource.许多 CDK 类都有
static from...
方法来获取对现有 AWS 资源的引用。 These methods are handy (or even necessary) when resources are shared between apps, but should be used only when you cannot modify the original CDK construct.当资源在应用程序之间共享时,这些方法很方便(甚至是必要的),但只有在您无法修改原始 CDK 结构时才应使用这些方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.