Search code examples
amazon-web-servicesaws-cloudformationserverless-framework

How can I ref API gateway endpoint in serverless?


I am using serverless.yml as the infra. framework. I create a lambda with a API gateway like below code:

functions:
  create:
    handler: posts.create
    events:
      - http:
          path: posts/create
          method: post
          authorizer: xxx:xxx:Lambda-Name

it will generate a endpoint for the API gateway. But how can I reference this endpoint in other place in the yml file?


Solution

  • Ref: ApiGatewayRestApi - ApiGatewayRestApi is a default Rest API logical ID.

    How do I get/reference API gateway restAPI id in serverless.yml?

    custom:
        webServiceEndpoint:
            Fn::Join:
              - ''
              - - 'https://'
                - Ref: ApiGatewayRestApi
                - '.execute-api.'
                - Ref: AWS::Region
                - '.amazonaws.com/'
                - ${self:provider.stage}