【问题标题】:How to set up Custom Domain names with Route53 in AWS SAM Cloud-Formation如何在 AWS SAM Cloud-Formation 中使用 Route53 设置自定义域名
【发布时间】:2020-06-30 21:02:40
【问题描述】:

原始问题:如何从 SAM Cloud-formation 中的 AWS APIGateway 域名中获取区域域名

编辑:我更改了问题,希望能获得更多流量到这个答案,因为它回答了几个问题,而不仅仅是我原来的问题。


我在尝试部署堆栈时收到以下错误:

resource DomainName does not support attribute type regionalDomainName in Fn::GetAtt

我的 yml 文件如下所示:

  PublicApi:
    Type: AWS::Serverless::Api
    Properties:
      Name: PublicApi
      ...
      EndpointConfiguration: REGIONAL

  DomainName:
    Type: AWS::ApiGateway::DomainName
    Properties:
      RegionalCertificateArn: "arn:aws:acm:${Region}:XXXXXXXXXXX:certificate/XXXXXXXXXXXXX"
      DomainName: !Sub ${Stage}.${name}
      EndpointConfiguration:
        Types:
          - REGIONAL

  myDNSRecord:
    Type: AWS::Route53::RecordSet
    Properties:
      HostedZoneId : Z1UJRXOUMOOFQ8
      Name: !Sub ${Stage}.${name}
      AliasTarget:
        HostedZoneId: Z1UJRXOUMOOFQ8 
        DNSName: !GetAtt DomainName.regionalDomainName
      Type: A

  UrlMapping:
    Type: AWS::ApiGateway::BasePathMapping
    DependsOn:
      - PublicApi
    Properties:
      DomainName: !Ref DomainName
      RestApiId: !Ref PublicApi
      Stage: !Ref Stage

以下来自DomainName documentation

"区域域名 与此自定义域名的区域端点关联的域名。您通过添加将自定义域名指向此区域域名的 DNS 记录来设置此关联。”

我很困惑我需要做什么才能使这个域名成为区域性的。

我在不同的迭代中也遇到了以下错误,我认为这应该可以解决:

“当 REGIONAL 处于活动状态时,无法为 EDGE 导入证书。”

在这方面的任何帮助将不胜感激!

【问题讨论】:

    标签: amazon-web-services yaml amazon-cloudformation serverless aws-sam


    【解决方案1】:

    我从几个不同的论坛中找到了针对不同问题的不同解决方案,最后提出了一个可行的模型。我希望这对将来的人有所帮助。

      PublicApi:
        Type: AWS::Serverless::Api
        Properties:
          Name: PublicApi
          StageName: ApiStage
          ...
          EndpointConfiguration: REGIONAL
    
      DomainName:
        Type: AWS::ApiGateway::DomainName
        Properties:
          RegionalCertificateArn: "arn:aws:acm:u${Region}:XXXXXXXX:certificate/XXXXXXXX"
          DomainName: stage.example.com
          SecurityPolicy: TLS_1_2
          EndpointConfiguration:
            Types:
              - REGIONAL
      LambdaDNS:
        Type: AWS::Route53::RecordSetGroup
        Properties:
          HostedZoneName:
            Ref: example.com.
          RecordSets:
            - Name:
                Fn::Sub: stage.example.com.
              Type: A
              AliasTarget:
                HostedZoneId: Z1UJRXOUMOOFQ8
                DNSName:
                  Fn::GetAtt:
                    - DomainName
                    - RegionalDomainName
      UrlMapping:
        Type: AWS::ApiGateway::BasePathMapping
        DependsOn:
          - PublicApi
          - PublicApiStage
        Properties:
          DomainName:
            Ref: DomainName
          RestApiId:
            Ref: PublicApi
          Stage: ApiStage
    

    对我来说关键位最终是 BasePathMapping 中的 DependsOn。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-10
      • 1970-01-01
      • 1970-01-01
      • 2021-09-01
      • 1970-01-01
      • 2023-03-31
      • 2016-04-07
      相关资源
      最近更新 更多