Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I schedule a lambda function execution with a lambda function?

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.

like image 209
xdumaine Avatar asked Feb 21 '17 02:02

xdumaine


People also ask

Can AWS Lambda Functions be scheduled?

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.

How do you call Lambda function in another lambda?

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.

How do I trigger Lambda function automatically?

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.

How do I deploy a lambda function on a schedule?

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.

How do I run a lambda function in AWS?

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.

What are scheduled events in AWS Lambda?

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.

How do I set a lambda function to run every 5 minutes?

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.


1 Answers

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.

like image 156
nirvana124 Avatar answered Oct 06 '22 23:10

nirvana124