Skip to content

When defining two API's with domains in the same hosted zone, the second API's Route 53 RecordSetGroups resource overwrites the first #1539

Description

@NickDobsonMO

Description:

When you define two AWS::Serverless::Api resources in the same template which have domains in the same Route 53 hosted zone the resulting Cloudformation template contains one AWS::Route53::RecordSetGroup which only includes the record set for the second API. The recordset for the first API is not present in the output and is lost.

During the transform, the logical id for the AWS::Route53::RecordSetGroup is generated using a hash of either the hosted zone name or hosted zone id. As the same hosted zone is used for both AWS::Serverless::Api resources domains, the logic name is the same and the AWS::Route53::RecordSetGroup created for the second AWS::Serverless::Api domain overwrites the first.

Steps to reproduce the issue:

  1. Create a template containing two gateways with domains in the same hosted zone:
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31

Resources:
    ApiGatewayOne:
        Type: AWS::Serverless::Api
        Properties:
            StageName: Prod
            Domain:
                CertificateArn: CertificateArn
                DomainName: api-one.domain.com
                Route53:
                    HostedZoneName: HostedZoneName

    ApiGatewayTwo:
        Type: AWS::Serverless::Api
        Properties:
            StageName: Prod
            Domain:
                CertificateArn: CertificateArn
                DomainName: api-two.domain.com
                Route53:
                    HostedZoneName: HostedZoneName
  1. Transform the SAM template to Cloudformation using the CLI or console.

Observed result:

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  ApiGatewayOne:
    Properties:
      Body:
        info:
          title:
            Ref: AWS::StackName
          version: '1.0'
        paths: {}
        swagger: '2.0'
    Type: AWS::ApiGateway::RestApi
  ApiGatewayOneDeploymentf9e2e3fce7:
    Properties:
      Description: 'RestApi deployment id: f9e2e3fce7ff39be96068344e44c14271beacd7e'
      RestApiId:
        Ref: ApiGatewayOne
      StageName: Stage
    Type: AWS::ApiGateway::Deployment
  ApiGatewayOneProdStage:
    Properties:
      DeploymentId:
        Ref: ApiGatewayOneDeploymentf9e2e3fce7
      RestApiId:
        Ref: ApiGatewayOne
      StageName: Prod
    Type: AWS::ApiGateway::Stage
  ApiGatewayDomainNamea053849895:
    Properties:
      DomainName: api-one.domain.com
      EndpointConfiguration:
        Types:
          - REGIONAL
      RegionalCertificateArn: CertificateArn
    Type: AWS::ApiGateway::DomainName
  ApiGatewayOneBasePathMapping:
    Properties:
      DomainName:
        Ref: ApiGatewayDomainNamea053849895
      RestApiId:
        Ref: ApiGatewayOne
      Stage:
        Ref: ApiGatewayOneProdStage
    Type: AWS::ApiGateway::BasePathMapping
  RecordSetGroupf6dbc85119:  # This RecordSetGroup only contains the second APIs recordsets
    Properties:
      HostedZoneName: HostedZoneName
      RecordSets:
        - AliasTarget:
            DNSName:
              Fn::GetAtt:
                - ApiGatewayDomainName9efebe563e
                - RegionalDomainName
            HostedZoneId:
              Fn::GetAtt:
                - ApiGatewayDomainName9efebe563e
                - RegionalHostedZoneId
          Name: api-two.domain.com
          Type: A
    Type: AWS::Route53::RecordSetGroup
  ApiGatewayTwo:
    Properties:
      Body:
        info:
          title:
            Ref: AWS::StackName
          version: '1.0'
        paths: {}
        swagger: '2.0'
    Type: AWS::ApiGateway::RestApi
  ApiGatewayTwoDeploymenta139d06cd0:
    Properties:
      Description: 'RestApi deployment id: a139d06cd0ba5773c1d94d9d67cd7eaf0b25121f'
      RestApiId:
        Ref: ApiGatewayTwo
      StageName: Stage
    Type: AWS::ApiGateway::Deployment
  ApiGatewayTwoProdStage:
    Properties:
      DeploymentId:
        Ref: ApiGatewayTwoDeploymenta139d06cd0
      RestApiId:
        Ref: ApiGatewayTwo
      StageName: Prod
    Type: AWS::ApiGateway::Stage
  ApiGatewayDomainName9efebe563e:
    Properties:
      DomainName: api-two.domain.com
      EndpointConfiguration:
        Types:
          - REGIONAL
      RegionalCertificateArn: CertificateArn
    Type: AWS::ApiGateway::DomainName
  ApiGatewayTwoBasePathMapping:
    Properties:
      DomainName:
        Ref: ApiGatewayDomainName9efebe563e
      RestApiId:
        Ref: ApiGatewayTwo
      Stage:
        Ref: ApiGatewayTwoProdStage
    Type: AWS::ApiGateway::BasePathMapping

Expected result:

Either two AWS::Route53::RecordSetGroup resources, one for each AWS::Serverless::Api domain. Or one AWS::Route53::RecordSetGroup containing the record sets for both AWS::Serverless::Api domains.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions