Issue
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")
Solution
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.
Answered By - yorodm
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.