SAM - Creating a new API Gateway with an existing Custom Domain

0

We are exploring using SAM for deployment and we want to use a single custom domain (e.g. api.example.com) and create a base path per microservice (e.g. api.example.com/svcA and api.example.com/svcB). Each microservice is its own project/repo and we want to keep it that way.

In working with SAM we found that it will always try to create the custom domain instead of using an existing one. This causes microservices to be undeployable because they try to create a custom domain that already exists.

Is it possible to do what I want? Is there an example of how to accomplish this?

1개 답변
1

This ended up being very easy to accomplish. I had been focused on the custom domain part so much I overlooked that I could simply create a BasePathMapping. The following worked fine for me:

  BasePath:
    Type: AWS::ApiGateway::BasePathMapping
    Properties:
      BasePath: my-service
      DomainName: !Ref DomainName # I pass this in as a parameter per environment.
      RestApiId: !Ref MainApi  # This is my AWS::Serverless::Api resource
      Stage: default

Edited by: StealthSid2 on Jul 16, 2020 12:12 PM

답변함 4년 전
  • @StealthSid2, could you share your template.yml for two of your projects? I'm struggling to accomplish the same thing. I can get one project to use BasePathMapping with domain, but when I try to take the same approach in my second microservice project I get this error when trying to deploy in SAM:

    api.hostname.com | Mapping already exists in stack arn:aws:cloudformation:us- east-1:...

    Essentially it says the mapping already exists.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠