amazon-web-services - 如何为 CfnDistribution 添加 Route53 别名?

标签 amazon-web-services amazon-cloudfront amazon-route53 aws-cdk

亚马逊有 this example了解如何为您的 CloudFrontWebDistribution 创建自定义别名:

import route53 = require('@aws-cdk/aws-route53');
import targets = require('@aws-cdk/aws-route53-targets');

new route53.AaaaRecord(this, 'Alias', {
  zone: myZone,
  target: route53.RecordTarget.fromAlias(new targets.CloudFrontTarget(distribution))
});

这看起来 super 简单。

但是,由于 Lambda@Edge 的限制,我不得不改用低级 CfnDistribution。有没有办法为那个创建别名?直接或使用一些巫术从低级 CfnDistribution 创建高级 CloudFrontWebDistribution 构造?

最佳答案

我从 aws-route53-targets 模块中提取了 CloudFrontTarget 代码并对其进行了调整,使其成为:

class CfnDistributionTarget implements route53.IAliasRecordTarget {
  private readonly distribution: CfnDistribution
  /**
   * The hosted zone Id if using an alias record in Route53.
   * This value never changes.
   */
  static readonly CLOUDFRONT_ZONE_ID = 'Z2FDTNDATAQYW2'
  constructor(distribution) {
    this.distribution = distribution
  }
  bind(_record: route53.IRecordSet): AliasRecordTargetConfig {
    return {
      hostedZoneId: CfnDistributionTarget.CLOUDFRONT_ZONE_ID,
      dnsName: this.distribution.attrDomainName
    }
  }
}

关于amazon-web-services - 如何为 CfnDistribution 添加 Route53 别名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59901382/

相关文章:

amazon-web-services - 在 AWS DNS/Route 53 记录中使用比较逻辑

laravel spatie/媒体库通过 cloudfront 提供来自 s3 的图像

node.js - 主页未解析裸域 URL

amazon-web-services - Terraform:如何在根目录下创建 api 网关 POST 方法?

angularjs - 从 Elastic Beanstalk 提供静态文件不起作用

amazon-cloudfront - 何时使用 AWS CloudfrontWebDistribution 以及何时使用 AWS Cloudfront Distribution

aws-lambda - AWS Lambda 触发器没有云端

dns - 使用Route53将请求转发到父域

java - 使用 DynamoMapper 和类 Annotation 创建具有全局二级索引的表

amazon-web-services - 数据管道(DynamoDB 到 S3)- 如何格式化 S3 文件?