0

I have 100 lambda functions. All of them have 2 distinct keywords in their function name -

  1. From_Table
  2. To_Table

For example, my function-names are: function1_To_Table, function2_From_Table etc. I have 100 such functions, 50 each side (To, From)

I want to create one event which invokes all functions that have above keywords in their name every 15 minutes. I don't want to create 100 events for all 100 lambdas.

Something like this: Run my function if function name contains - To_Table or From_Table

Can anyone help me with this?

Hello.World
  • 570
  • 6
  • 19
  • Can you please elaborate the scenario? – Gourab Paul Aug 22 '19 at 15:33
  • @GourabPaul Edited the question. I have 100 functions like `func1_To_Table`, `func2_From_Table` etc. Now I want all these to run every 15 mins. Rather than creating 100 events I want to create one events like - `Run my function if function name contains - To_Table or From_Table` – Hello.World Aug 22 '19 at 15:36

2 Answers2

1

I think your approach is wrong. Creating 1 event for each lambda not the right solution, I agree with you there. Instead create one lambda function that can iterate over and call each of the 50 other functions on its own, then schedule that function in Cloudwatch events to trigger every 15 minutes. One event, one function that executes each 50 to_from or from_to functions.

Reference Can an AWS Lambda function call another.

EDIT: Just thought about something, are your functions long running? If they take a while to complete then the first function may time out before completing all 50 other functions. You may need to setup SNS or SQS to trigger the other functions.

Michael Quale
  • 486
  • 3
  • 12
  • When I iterate over all functions and use invoke function, it times out in 15 mins. – Hello.World Aug 22 '19 at 19:23
  • It doesn't seem like an elegant solution will work in your use case. In keeping with AWS best practices and DRY concepts. It would not make sense to create 50 events like you mentioned in your question. Have you tried using step functions? This might make sense, to have a step function that calls each lambda function, then have that run on a Cloudwatch event every 15 minutes. https://aws.amazon.com/getting-started/tutorials/create-a-serverless-workflow-step-functions-lambda/ – Michael Quale Aug 23 '19 at 16:00
  • I have a invoke function which invokes using type - `Event`. This runs within 45 seconds on my laptop but times out on AWS lambda – Hello.World Aug 23 '19 at 16:03
  • One more comment, its super easy to set up 50 iterations of an aws resource, if you use Terraform and the count function. – Michael Quale Aug 23 '19 at 16:04
  • Are you allocating enough CPU or memory for that function in Lambda? – Michael Quale Aug 23 '19 at 16:05
  • Yes there is enough memory. – Hello.World Aug 23 '19 at 16:06
1

first of all AWS doesn't provide any function to invoke a lambda with regex or using wildcard. In order to invoke a all your functions, first you need to get the list of lambda functions. using aws cli you can run this command

1 - aws lambda list-functions

2 - you extract the functions which matches the keywords i.e to_from, from_to from the response of list-functions

3 - create a look to invoke all the extracted functions (aws lambda invoke --function-name)

aws also has api to perform all the functions in aws-sdk or in boto3

  • What is the invoke functions executes a function that takes 15 mins + and times out? Is there a way that invoke_function can send the functions to queue and itself stops running? – Hello.World Aug 22 '19 at 18:45
  • we can invoke all functions asynchronously at once Triggering lambda wont have to wait for completion. It just depends on requirement, What I understood about the questions is @michael knows that functions will take not more than 15 minutes. – Nouman Khalid Aug 22 '19 at 19:22
  • This sounds like a task for step functions, but If it takes more than 15 minutes to iterate through all 50 lambda's why run it every 15 minutes? – Michael Quale Aug 23 '19 at 16:03