2

I was looking at a tutorial on writing a Lambda function in AWS using Node.js version 8. The template code shown in the tutorial when a new function is created looks like

exports.handler = async (event, context) => {
    //
};

but when I create one in my console using Node.js 14.x runtime, there is no context parameter.

Will the anonymous function accept a context parameter? What is the significance of it not being included in the later version of Node.js?

1
  • 1
    The second parameter always is the context. Commented Jun 19, 2021 at 2:37

1 Answer 1

1

The context parameter can be omitted. But if you need it, it has to be the second parameter.

So both of these are fine:

exports.handler = async (event, context) => {};

and without context:

exports.handler = async (event) => {};

You can read more about NodeJS handlers and context in the official AWS documentation:

  1. AWS Lambda function handler in Node.js
  2. AWS Lambda context object in Node.js
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.