使用 viewerCertificate 创建 CloudFrontWebDistribution,如何配置

Create CloudFrontWebDistribution with viewerCertificate, how to configure

我正在通过 AWS-CDK 将我的单页应用程序部署到 S3 存储桶。

当前堆栈代码为:

this.distribution = new CloudFrontWebDistribution(this, `${this.props.applicationName}Distribution`, {
      originConfigs: [
        {
          s3OriginSource: {
            s3BucketSource: this.dashboardBucket,
            originAccessIdentity: dashboardIdentity
          },
          behaviors: [{
            isDefaultBehavior: true
          }],
        },
      ],
      aliasConfiguration: {
        acmCertRef: awsConfig.acm_arn,
        names: [url]
      },
      errorConfigurations: [
        {
          errorCode: 403,
          responseCode: 200,
          responsePagePath: '/'
        },
        {
          errorCode: 404,
          responseCode: 200,
          responsePagePath: '/index.html'
        }
      ]
    });

但是,在 AWS-CDK 1.133 中,我收到了 aliasConfiguration 已弃用的消息。所以我正在查看 viewerCertificate: ViewerCertificate.fromAcmCertificate() 但我不确定如何使用它。

之前我可以参考我已经在证书管理器中创建的证书的 ARN。 我可以使用 Certificate class 获取现有 ACM 资源的引用并将其与 ViewerCertificate 一起使用吗?

AWS 的文档在示例中不是很清楚,只是所有参考。

是的,您可以使用 Certificate 构造来获取对现有证书的引用。使用 Certificate.fromCertificateArn()

viewerCertificate: ViewerCertificate.fromAcmCertificate(
    Certificate.fromCertificateArn(this, "my_cert", awsConfig.acm_arn)
)

实际上,所提出的解决方案不允许我添加自定义 cname。 幸运的是,我找到了另一个解决方案:

viewerCertificate: {
  aliases: [url],
  props: {
    acmCertificateArn: awsConfig.acm_arn,
    sslSupportMethod: 'sni-only',
    minimumProtocolVersion: 'TLSv1.1_2016',
  }
},

此处提到:https://github.com/aws/aws-cdk/issues/1802