4

I am working with a lambda function which does a requests.post('url', json_data) to my application endpoint, and this is working fine .

the only problem is that lambda function is getting called multiple times , I am using python ( boto3 ) for creating lambda handler function , and when searching for the solution I keep seeing context.succeed ( but it turns out that this option is only available for node not python), I got the below options for dir(context).

['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'aws_request_id', 'client_context', 'function_name', 'function_version', 'get_remaining_time_in_millis', 'identity', 'invoked_function_arn', 'log', 'log_group_name', 'log_stream_name', 'memory_limit_in_mb']

Can someone please help to get context.succeed equivalent in python (boto3), or a way to get stop the lambda function getting executed multiple times in python . Thanks in Advance.

lazarus
  • 677
  • 1
  • 13
  • 27
  • I'm not sure how `context.succeed` keeps a function from being executed multiple times. The equivalent of `context.succeed` in Python is simply to return/exit the function. Why exactly do you think the function is being called multiple times? – Mark B Jun 25 '18 at 18:23
  • 1
    Just to clarify my use case, I am receiving mails from ses, and storing them to a S3 bucket, and the S3 bucket is triggering the lambda function.. So I wanted the mail information which is getting saved in S3 bucket. Hence I am doing a post request to my application endpoint , which receives the bucket key as json data. And I can parse the mail from there.. I am not sure why this is getting called multiple times, but I am storing mail into Bucket only once. – lazarus Jun 25 '18 at 18:30
  • https://stackoverflow.com/q/32064038/3188050 , based on this question ,it seems I have to increase the time out value – lazarus Jun 25 '18 at 18:36
  • Increasing the timeout value wouldn't stop the function from being called multiple times. The question is, is the function really being called multiple times (which can only be solved by looking at whatever is calling it) or is the function erroring out somehow and being retried (which can only be fixed by looking at the error in the logs and then proceeding to fix the actual error/issue). Right now you are basically just trying random things in the hope something fixes it. – Mark B Jun 25 '18 at 18:55
  • thanks @MarkB, it seems like after I am doing requests.post('my_app_endpoint',json_data) , it is waiting for the response , and while its waiting , it is doing three more retries ( which ends up doing multiple lamda triggers) – lazarus Jun 25 '18 at 19:11

1 Answers1

2

In my case, just returning a True value from the handler stopped calling the handler multiple times during S3 events.

def index(event, context):
    # actions here

    return True
romeo14
  • 516
  • 5
  • 13