I'm looking for the ability to programmatically schedule a lambda function to run a single time with another lambda function. For example, I made a request to myFirstFunction
with date
and time
parameters, and then at that date and time, have mySecondFunction
execute. Is that possible only with stateless AWS services? I'm trying to avoid an always-on ec2 instance.
Most of the results I'm finding for scheduling a lambda functions have to do with cloudwatch and regularly scheduled events, not ad-hoc events.
You can set up a rule to run an AWS Lambda function on a schedule. This tutorial shows how to use the AWS Management Console or the AWS CLI to create the rule. If you would like to use the AWS CLI but have not installed it, see the AWS Command Line Interface User Guide.
Setting up the Policy for ParentFunction. In order to allow the ParentFunction to call the ChildFunction, we need to provide the ParentFunction with specific rights to call another lambda function. This can be done by adding specific policies to a role and then assign that role to the lambda function.
For Function, Select the function name. For Configure details, Under the Rule definition, enter a name for the rule and then provide a short description. State should be Checked (Enabled). Necessary permissions for the cloudwatch event rule will be automatically added to execute the Target lambda functions.
Choose Deploy. Create a rule to run the Lambda function you created in step 1 on a schedule. You can use either the console or the AWS CLI to create the rule. To use the AWS CLI, you first grant the rule permission to invoke your Lambda function. Then you can create the rule and add the Lambda function as a target.
The execution of a Lambda function can be done on a regular basis through AWS Event Bridge, where you create a rule that runs on a schedule and triggers your Lambda. The Event Bridge is a serverless event bus connecting your applications and services by passing data (or events) from a source to a destination.
Scheduled events are used to execute Lambda function after an interval which is defined in cloudwatch services. They are best used for working on cron jobs along with AWS Lambda. This chapter will explain with simple example how to send mail after every 5 minutes using scheduled events and AWS Lambda.
Use the following put-targets command to add the Lambda function that you created to this rule so that it runs every five minutes: Create the file targets.json with the following contents: At least five minutes after completing Step 2, you can verify that your Lambda function was invoked.
This is a perfect use case for aws step functions.
Use Wait
state with SecondsPath
or TimestampPath
to add the required delay before executing the Next State.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With