Hello,
I’m new using Serverless and first time sharing a question. I have to say is awesome!
I’m performing a POST request using API Gateway + Lambda. When I test it on Lambda via console there’s no problem, but when testing in API Gateway there’s a strange error:
{
"errorType": "TypeError",
"errorMessage": "Cannot read property 'requestTimeEpoch' of undefined",
"trace": [
"TypeError: Cannot read property 'requestTimeEpoch' of undefined",
" at Runtime.handler (/var/task/serverless_sdk/index.js:9:86135)",
" at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)",
" at process._tickCallback (internal/process/next_tick.js:68:7)"
]
}
And in final lines of the log:
Fri Sep 06 14:32:43 UTC 2019 : Endpoint response body before transformations: {"errorType":"TypeError","errorMessage":"Cannot read property 'requestTimeEpoch' of undefined","trace":["TypeError: Cannot read property 'requestTimeEpoch' of undefined"," at Runtime.handler (/var/task/serverless_sdk/index.js:9:86135)"," at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"," at process._tickCallback (internal/process/next_tick.js:68:7)"]}
Fri Sep 06 14:32:43 UTC 2019 : Method response body after transformations: {"errorType":"TypeError","errorMessage":"Cannot read property 'requestTimeEpoch' of undefined","trace":["TypeError: Cannot read property 'requestTimeEpoch' of undefined"," at Runtime.handler (/var/task/serverless_sdk/index.js:9:86135)"," at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"," at process._tickCallback (internal/process/next_tick.js:68:7)"]}
Fri Sep 06 14:32:43 UTC 2019 : Method response headers: {X-Amzn-Trace-Id=Root=1-5d726e0b-dcef5e8d6fab2e410341b7ca;Sampled=0, Access-Control-Allow-Origin=*, Content-Type=application/json}
Fri Sep 06 14:32:43 UTC 2019 : Successfully completed execution
Fri Sep 06 14:32:43 UTC 2019 : Method completed with status: 200
Please, can you share some ideas about how to solve it?. Below is the service:
service: eureky-imageProcessor
app: eureky
org: ecalle17
# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
# frameworkVersion: "=X.X.X"
provider:
name: aws
runtime: nodejs10.x
stage: ${opt:stage, 'dev'}
region: us-west-2
environment:
REGION: ${self:provider.region}
functions:
imageProcessor:
handler: handler.imageProcessor
events:
- http:
description: Process image and returns a package with converted resources
path: imgProcessor
method: post
cors: true
and the lambda function:
‘use strict’;
module.exports.imageProcessor = function (event, context, callback) {
console.log(event)
if (event.httpMethod === 'POST' && event.body) {
const response = {
statusCode: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*", // Required for CORS support to work
"Access-Control-Allow-Credentials": true // Required for cookies, authorization headers with HTTPS
},
body: JSON.stringify({
message: 'Go Serverless v1.0! Your function executed successfully!',
})
};
callback(null, response)
}
};
Thank you!