Hello.World
Hello.World

Reputation: 740

Running lambda function where function name like 'my_function'

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?

Upvotes: 0

Views: 575

Answers (2)

Nouman Khalid
Nouman Khalid

Reputation: 108

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

Upvotes: 1

Michael Quale
Michael Quale

Reputation: 607

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.

Upvotes: 1

Related Questions