0

I built my lambda function using python with the standard required format

def lambda_handler(event, context):

When I run it, everything is fine except I get all the info I call in the logs because the response is null. The response is null because I haven't actually called the function, I only defined it. However when I call the function, I need the argument (event, context).

When defining the function and testing in the AWS Lambda console, the context variable seems to be supplied for me. But when I call the function without the variables, I get the error below.

lambda_handler() missing 2 required positional arguments: 'event' and 'context'

If I enter the event and context variables in my function, it says they are not defined. When I called the function from within itself, it says that the variable context is not defined.

I can provide the data for the event variable, but I'm not sure what is supposed to go in the context variable. Am I not calling my function correctly?

3
  • 2
    How are you invoking your lambda function? Commented Nov 12, 2019 at 3:46
  • You do not need to call the function. Lambda will call it after running your definition. Commented Nov 13, 2019 at 3:37
  • Question needs to supply some code in order to be able to diagnose the problem. It asks "Am I not calling my function correctly?" without even showing how the function is being called. Voting to close unless detail provided. Commented Sep 1, 2023 at 3:40

1 Answer 1

1

You don't need to provide the context argument. Lambda supplies this for you. When Lambda runs your function, it passes a context object to the handler. This object provides methods and properties that provide information about the invocation, function, and execution environment. The context argument has properties such as function_name, function_version, memory_limit_in_mb, among others. See more information here: https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html

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.