1

I have 50 lambda functions. Now I wrote a script to invoke these 50 functions every 15 minutes, something like this:

import boto3
import pickle

def Handler(event, context):

    #read exams functions from pickle
    with open('result.pickle', 'rb') as file:
        all_functions = pickle.load(file)
        functions = all_functions['func']
        print('check functions')

    for items in functions:
        if 'FromDB' in items:
            print(items)
            lambda_client = boto3.client('lambda')
            response = lambda_client.invoke(FunctionName = items, InvocationType = 'Event')
            print(response)
        else:
            continue

I created a deployment package with boto3 package and the pickle file in it. When I execute this in lambda management console, 2 things I notice:

  1. check functions is printed twice in logs, event though there is just one single print

  2. The logs show either 1 or 2 functions that are executed. It doesn't print all functions, which means those functions are never invoked.

This script however runs on my local machine in 24 seconds and all functions are executed perfectly. Can someone help me to run this script on AWS?

My pickle file:

with open('result.pickle', 'rb') as file:
    all_functions = pickle.load(file)
    functions = all_functions['func']
print(functions)

{'myfunc_1', 'myfunc_2', 'myfunc_3', 'myfunc_4', 'myfunc_5'}

The above are aws lambda functions itself which are to be invoked

2
  • Chances are that your pickle file contains the lambda function itself. If that is the case, it might be falling prey to recurring calls and hence never really terminating correctly. Eventually AWS might be taking care of terminating it. Posting content of your pickle file would be more helpful in case the above is not an issue Commented Sep 16, 2019 at 19:26
  • "Chances are that your pickle file contains the lambda function itself" - what do you mean by that? Commented Sep 16, 2019 at 19:34

1 Answer 1

0

Make sure that the execution timeout of the lambda function is enough so that it has time to invoke all of the other lambdas.

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

The invoke type is 'Event'. Shouldn't wait for function to complete
I never said that it should wait till the function to complete, i said your lambda is probably timing out before it can execute all of your code.
So the timeout is set to 900 seconds. Also the same thing runs on my laptop in 24 seconds

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.