首页 > 解决方案 > 使用无服务器框架将 Route 53 中的 DNS 记录添加和更新到 Cloudfront

问题描述

我目前正在扩展这个 repo。它包含使用无服务器框架将 sapper/svelte webapp 部署到 AWS 的源代码。我正在考虑如何将serverless.ymlRoute53 DNS 路由扩展到 Cloudfront,但我似乎无法理解它。serverless -domain-manager插件似乎是为 Route53 到 API Gateway 路由而设计的,但我仅使用 Cloudfront、S3 存储桶和 Lambda@Edge 处理程序服务器端渲染应用程序来部署我的应用程序。

标签: dnsamazon-route53serverless-frameworkserverlessaws-serverless

解决方案


我在这里做过类似的事情。

我已经修剪serverless.yml了相关部分:

WebAppCloudFrontDistribution:
    Type: AWS::CloudFront::Distribution
    DependsOn:
      - WebAppS3Bucket
    Properties:
    DistributionConfig:
        ### content trimmed
        Aliases:
          - 'www.example.com'
        ### content trimmed
        ViewerCertificate:
          AcmCertificateArn: 'CertificateArn' # in the linked repo I'm using a plugin to auto generate the certificate
          SslSupportMethod: sni-only
WebsiteDNSName:
    Type: AWS::Route53::RecordSetGroup
    Properties:
    HostedZoneId: 'HostedZoneId' # Taken from the AWS Console
    RecordSets:
      - Name: 'www.example.com'
        Type: A
        AliasTarget:
            HostedZoneId: Z2FDTNDATAQYW2
            DNSName: !GetAtt [WebAppCloudFrontDistribution, DomainName]
            EvaluateTargetHealth: false

推荐阅读