1

I'm using a lambda to invoke another one with this piece of code:

import boto3
import json

# Lambda Handler
def lambla_handler(event,context):

    lam = boto3.client('lambda', region_name='sa-east-1')

    try:
        response = lam.invoke(FunctionName='water_types', InvocationType='RequestResponse') 
    except Exception as e:
        print(e)
        raise e
    print(response)

Everything is working fine, however when the lambda 'water_types' is getting this error:

water_types() takes 0 positional arguments but 2 were given: TypeError
Traceback (most recent call last):
File "/var/runtime/awslambda/bootstrap.py", line 250, in handle_event_request
result = request_handler(json_input, context)
TypeError: water_types() takes 0 positional arguments but 2 were given

As I can see, I'm not sending any arguments. Any idea how to fix it?

def water_types(): 
   return print("water updated: 90")
2
  • Can you please show the handler of water_types? I thinks you're missing the mandatory (event, context) arguments Commented Apr 8, 2019 at 19:39
  • Yes, it is. Do I always need to use them? Commented Apr 8, 2019 at 19:42

1 Answer 1

3

If water_types is the handler of a function (which according to your code it is) you need to follow AWS guidelines on how to create lambda functions with Python

A lambda handler needs to have an structure similar to

def handler_name(event, context): 
    ...
    return some_value

The lambda runtime will provide values for event and context when it calls the handler.

So TL;DR, your function needs to look like this

def water_types(event, context): 
   return print("water updated: 90")

You're not required to do anything with those parameters, but they need to be there.

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.