How to set up Custom Domain names with Route53 in AWS SAM Cloud-Formation
Asked Answered
R

1

5

ORIGINAL QUESTIONS: How to get RegionalDomainName out of a AWS APIGateway DomainName in SAM Cloud-formation

EDIT: I changed the question to hopefully get more traffic to this answer as it answers several questions not just my original one.


I am getting the following error when I try and deploy my stack:

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

My yml file looks like the following:

  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

The following is from the DomainName documentation:

"RegionalDomainName The domain name associated with the regional endpoint for this custom domain name. You set up this association by adding a DNS record that points the custom domain name to this regional domain name."

I am confused as to what I need to do to make this DomainName Regional.

I have also been getting the following Errors in different iterations, that I thought this should fix:

"Cannot import certificates for EDGE while REGIONAL is active."

Any help on this front would be much appreciated!

Replevin answered 19/3, 2020 at 17:18 Comment(0)
R
7

I found from several different forums different solutions to different problems and finally came up with a working model. I hope this helps someone out in the future.

  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

The key bit for me ended up being the DependsOn in the BasePathMapping.

Replevin answered 19/3, 2020 at 18:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.