2

I have been working with AWS SAM and API first project - we have our API specified as an OpenAPI with AWS API GW extensions.

For integration testing, we use local API Gateway (through sam local start-api, which works fine with integrated endpoints from SAM template.yaml.

What I cannot figure out is whether local api supports mocked endpoints. In my desperate attempts, I went straight to API GW on AWS console and created test API and put mock configuration there. This worked when tested through API GW console (I saw mocked response and everything). I deployed API and exported OpenAPI from dev stage. Then I pasted this into my OpenAPI specification and started sam local start-api.

My configuration looks like this

/accounts/{accountId}/documents:
parameters:
  - $ref: '#/components/parameters/accountId'
get:
  operationId: ListAccountDocuments
  summary: List all account-based documents.
  description: |
    ...
  responses:
    200:
      description: OK
  x-amazon-apigateway-integration:
    type: "mock"
    responses:
      default:
        statusCode: "200"
        responseTemplates:
          application/json: "{\n    \"message\": \"hello\"\n}"
    requestTemplates:
      application/json: "{\"statusCode\": 200}"
    passthroughBehavior: "when_no_match"

When I curl curl localhost:3000/accounts/1/documents then I get 403 - Missing Token, which API GW throws when there is no integration.

Does AWS local API GW support mocks? I was not able to find that answer in documentation.

Or am I doing something wrong?

Martin Macak
  • 3,507
  • 2
  • 30
  • 54

0 Answers0