0
votes

When I use lambda console test to test lambda, I found the event I specified in console is different than the event sent from API gateway. The event from API gateway is the complete http request object structure. Below is an example of that.

{ resource: '/screenshot',
path: '/screenshot',
httpMethod: 'POST',
headers: null,
multiValueHeaders: null,
queryStringParameters: null,
multiValueQueryStringParameters: null,
pathParameters: null,
stageVariables: null,
requestContext: 
{ path: '/screenshot',
accountId: '286334053171',
resourceId: 'slne19',
stage: 'test-invoke-stage',
domainPrefix: 'testPrefix',
requestId: 'd091e8bf-7948-11e9-951d-3b38e4cc6ad6',

But the event is defined in lambda console is just a JSON object. How can I create a same test event in console to mock the API gateway event?

1

1 Answers

2
votes

When you configure a test event in the Lambda Console, you can select from a set of event templates. This includes an API Gateway proxy event:

enter image description here

If you use this method you'll have to configure the keys for your specific invocation.

Alternatively, you can console.log (or language equivalent), the event (first argument) argument to the lambda handler. This will give you the precise JSON object that you used in the API Gateway test- without requiring you to edit the template event.