简体   繁体   English

如何使用 AWS CDK 将域别名添加到现有 CloudFront 分配

[英]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?:ICertificatedomainNames?: 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.

相关问题 通过 AWS CDK 重新使用现有 CloudFront 分配 - Re-use existing CloudFront distribution with AWS CDK 如何使用 AWS CDK 将现有 Lambda 函数的别名指定为 DynamoDB 触发器? - How do I specify an existing Lambda function's alias as a DynamoDB trigger using the AWS CDK? AWS CDK,为 Route53 中现有的云前端分配创建别名记录 - AWS CDK, creating an alias record for existing cloud front distribution in Route53 使用 AWS CDK 配置具有 S3 源和自定义源 (ELB) 的 CloudFront 分配 - Configuring CloudFront distribution with S3 Origin and Custom Origin (ELB) using AWS CDK 域名已与“现有”CloudFront 分配关联 - Domain name already associated with an "existing" CloudFront distribution 域无法解析 AWS Cloudfront 分配 - Domain cannot resolve AWS Cloudfront distribution 如何通过cloudformation向现有的Cloudfront发行中添加新来源? - How to add new origins to an already existing cloudfront distribution through cloudformation? aws-cdk 将 Lambda 函数与 CloudFront Web 分配相关联 - aws-cdk Associate Lambda Function with CloudFront Web Distribution 如何使用CloudFormation向CloudFront分配提供备用域名(CNAME)? - How to provide Alternate Domain Names (CNAMEs) to the CloudFront distribution using CloudFormation? 使用Ruby AWS开发工具包为Cloudfront发行版创建Route53别名 - Using Ruby AWS SDK to create a Route53 alias to a Cloudfront distribution
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM