Search code examples
aws-api-gatewayserverless

How can I export the AWS API Gateway Endpoints to file (or similar) after deploying?


I am using the AWS API Gateway to mock different APIs and I want to use those endpoints in my application (which is not a lambda).

So my idea was to somehow reference those endpoints from a file like a json, but for that I need to get them exported every time I deploy.

Is there any way to archive this?


Solution

  • It depends on which stack you are using to deploy API gateway.

    For example,

    Outputs:
     myapi:
       Type: AWS::ApiGatewayV2::Api
       Properties:
         Name: MyAPI
         ProtocolType: HTTP
     APIEndpoint:
       Description: endpoint of api
       Value:
         Fn::Join:
           - ""
           - - https://
             - Ref: myapi
             - .execute-api.ap-southeast-1.amazonaws.com/
       Export:
         Name: APIEndpoint