The current execution environment still expects the callback to be called. Need to support async pattern.
@brianjd , anyway, you will need to do the following:
rm -rf node_modules
nvm install 8.11.1
nvm use 8.11.1
npm install
npm install -g serverless
Even though, it will not fix the issue, because serverless itself should support lambda with Node 8.10
You will need v3.20.0 or greater of serverless-offline to have it work.
Just tested serverless-offline version 3.20.1, and the callback is still expected to be called.
The following functions work on AWS Lambda with nodejs8.10. Also, all the functions works fine with sls invoke (local and deployed).
However, only the last two work with serverless-offline. The first one timesout.
import { APIGatewayEvent, Context, Callback, APIGatewayProxyResult } from "aws-lambda";
export async function ping(event:APIGatewayEvent, context:Context):Promise<APIGatewayProxyResult> {
return { statusCode:200, body:JSON.stringify({msg: 'ping' }) };
};
export async function pingCallback(event:APIGatewayEvent, context:Context, callback:Callback) {
callback(null, { statusCode:200, body:JSON.stringify({msg: 'ping' }) });
};
export function pingCallbackSync(event:APIGatewayEvent, context:Context, callback:Callback) {
callback(null, { statusCode:200, body:JSON.stringify({msg: 'ping' }) });
};
The async and the no longer need for callback was implemented in nodejs8.10 runtime - https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html.
Are there any plans to support the syntax demonstrated in the first example that @chrisdchristo shared above?
Namely:
import { APIGatewayEvent, Context, Callback, APIGatewayProxyResult } from "aws-lambda";
export async function ping(event:APIGatewayEvent, context:Context):Promise<APIGatewayProxyResult> {
return { statusCode:200, body:JSON.stringify({msg: 'ping' }) };
};
@aoggz this works all good in latest release.
Note, that the fix doesn't support per-lambda runtime configuration. You need to set runtime: nodejs8.10 for the whole provider otherwise it won't work, e.g.:
provider:
name: aws
runtime: nodejs8.10
I still can't get this to work, running on ^3.25.6. I have the provider config listed above, and am using the following:
export const ping = async () => ({message: 'pong'});
With the above, I see the request and the response, but I dont see the response in my curl/browser.
This format is documented: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html#nodejs-prog-model-handler-example under the second code block:
exports.myHandler = async function(event, context) {
console.log("value1 = " + event.key1);
console.log("value2 = " + event.key2);
return "some success message";
// or
// throw new Error(“some error type”);
}
If i send {statusCode: 200, body: {message: 'pong'}}, it works fine.
Same here. I am on serverless-offline 3.25.10. Is this getting solved?
Why is this closed for almost 3 months now? The issue is still there:
module.exports.test = function(event, context) {
return {
status: 'hello'
};
};
This results in serverless-offline complaining with:
Serverless: The first request might take a few extra seconds
Serverless: Replying timeout after 30000ms
I am on version 3.31.3.
@pkout The function in your snippet lacks the async keyword.
That said, I'm seeing some odd behaviour here with the client complaining it never received a response despite the plugin suggesting everything is ok. I've not yet quite dug in enough to decide if it's an issue with this plugin or something I'm doing, I may be back again at some point...
Most helpful comment
Just tested
serverless-offlineversion3.20.1, and the callback is still expected to be called.The following functions work on AWS Lambda with
nodejs8.10. Also, all the functions works fine withsls invoke(local and deployed).However, only the last two work with
serverless-offline. The first one timesout.The
asyncand the no longer need forcallbackwas implemented innodejs8.10runtime - https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html.