0
votes

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?

1
How are you invoking your lambda function? - Jorge Garcia
You do not need to call the function. Lambda will call it after running your definition. - John Rotenstein

1 Answers

1
votes

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