aws / serverless-application-model

The AWS Serverless Application Model (AWS SAM) transform is a AWS CloudFormation macro that transforms SAM templates into CloudFormation templates.
https://aws.amazon.com/serverless/sam
Apache License 2.0
9.36k stars 2.38k forks source link

Unable to map httpapi to exisiting customdomain #2208

Open rockey5520 opened 3 years ago

rockey5520 commented 3 years ago

Description:

I am trying to create a httpapi and map to an exisitng custom domain

Steps to reproduce:

Sample template.yml file

Resources:
  HttpApi:
    Type: AWS::Serverless::HttpApi
    Properties:
      StageName: !Ref StageName
      Tags:
        Tag: Value
      AccessLogSettings:
        DestinationArn: !GetAtt AccessLogs.Arn
        Format: $context.requestId
      StageVariables:
        StageVar: Value
      FailOnWarnings: True
      CorsConfiguration:
        AllowOrigins:
          - "*"
        AllowHeaders:
          - origin
          - content-type
          - x-amz-date
          - authorization
          - x-api-key
          - x-amz-security-token
        AllowMethods:
          - GET
          - POST
          - OPTIONS
          - PATCH
          - DELETE
        MaxAge: 0
      Domain:
        DomainName: x.x.x
        CertificateArn: arn
        EndpointConfiguration: REGIONAL
        Route53:
          HostedZoneId: XXXXXXXXXXX
        BasePath:
          - /banks

Observed result:

The domain name you provided already exists.    
                                                                                                                                                      (Service: AmazonApiGatewayV2; Status Code: 400; 
                                                                                                                                                      Error Code: BadRequestException; Request ID:    
                                                                                                                                                      ; Proxy:    
                                                                                                                                                      null) 

Expected result:

Map created httpapi to the custom domain and under paths given as per the template section BasePath

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Ubuntu
  2. sam --version: 1.16.0
  3. AWS region: eu-west-1

Add --debug flag to command you are running

CoshUS commented 3 years ago

Hey @rockey5520, SAM always creates a AWS::ApiGatewayV2::DomainName resource if DomainName is specified. https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-generated-resources-httpapi.html To use existing custom domain, you can remove DomainName and use AWS::ApiGatewayV2::ApiMapping resource instead. Closing. Let me know if there are other issues.

github-actions[bot] commented 3 years ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

rockey5520 commented 3 years ago

Hey, @CoshUS I suppose your suggestion works and fits nicely for hello-world type applications. but this is not the ideal way of building mapping API to an existing domain which is already having several mappings from other API's

This approach only makes things complex by removing touching the components(API mapping, in turn downtime) during deployment. can we get this issue to be converted as a feature for sam cli?

CoshUS commented 3 years ago

@rockey5520 Sounds good. I'll transfer this to SAM repo and the feature request would be: Add support for using existing custom domains for AWS::Serverless::HttpApi and AWS::Serverless::Api

rockey5520 commented 3 years ago

@CoshUS Thank you

hoffa commented 1 year ago

Tangentially related request in https://github.com/aws/serverless-application-model/issues/2778#issuecomment-1382368707