How to create a Mock API Gateway endpoint

Hi everyone,

I’m trying to build a Mock API Gateway endpoint and I’m having troubles with the response.

Looking at the documentation, add a custom response template should be something like

response:
headers:
Content-Type: “‘text/html’”
template: $input.path(‘$’)

Based on Serverless Framework - AWS Lambda Events - REST API (API Gateway v1)

For now it is a proof of concept, so only trying to return a mocked json.

This is my sample:

service: new-service
provider:
name: aws
runtime: nodejs6.10
stage: dev
profile: devProfile
region: eu-west-1
functions:
serverlessMockFunction:
handler: index.handler
description: lambda function created using serverless framework (MOCK)
memorySize: 512
timeout: 10
role: customLambdaExecRole
events:
- http:
path: greetingsMock
method: get
request:
passThrough: WHEN_NO_MATCH
template:
application/json: ‘{“statusCode”: 200}’
integration: mock
cors: true
response:
headers:
Cache-Control: “‘max-age=120’”
Content-Type: “‘application/json’”
template: ‘{“statusCode”: 200}’
resources:
Resources:
customLambdaExecRole:
Type: AWS::IAM::Role
Properties:
Path: /
RoleName: customLambdaExecRole
AssumeRolePolicyDocument:
Version: ‘2012-10-17’
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action: sts:AssumeRole

When I call the function I got this error:

Response Body

{
“message”: “Internal server error”
}

Logs

Execution log for request test-request
Starting execution for request: test-invoke-request
HTTP Method: GET, Resource Path: /greetingsMock
Method request path: {}
Method request query string: {}
Method request headers: {}
Method request body before transformations:
Endpoint response body before transformations:
Endpoint response headers: {}
Execution failed due to configuration error: No match for output mapping and no default output mapping configured
Method completed with status: 500

Any ideas?

Thanks in advance!