Bits and Pieces

Insightful articles, step-by-step tutorials, and the latest news on full-stack composable software development

Follow publication

Create an AWS Lambda Function that Dynamically Schedules its Next Runtime

Shadid Haque
Bits and Pieces
Published in
4 min readFeb 8, 2021

--

Photo by Black Chitsulo on Unsplash

Have you ever scheduled a meeting in Gmail, Outlook or Calendly? This is a classic example of a scheduled cron job.

Once you schedule a meeting and add participants it sends out invitations to everyone. Let’s say in this scenario some people accept the invite few don’t. People who accept the invitation of the meeting then get a reminder 30 minutes before the scheduled meeting time. They again get another reminder notification 5 minutes before the scheduled meeting time.

There are numerous applications of scheduled cron job such as the one above. In this article, we will build a scheduled cron job using AWS lambda and discuss how we can create a lambda function that can dynamically schedule its next runtime.

We will be using the following services provided by AWS for this exercise.

  1. Lambda function
  2. Cloudwatch Events

Lets create our lambda function

First of all, we will go ahead and create a simple lambda function (you can use a boilerplate or start from scratch).

The first order of business here is to figure out when we want to run the lambda next. Ideally we would write some business logic to determine this. However, for the sake of this tutorial we will assume that we want to run the lambda 30 minutes from its first runtime.

We first need to create a scheduled expression. This expression is a string value that can be passed into a cloud-watch event. To create an expression we will add the following code.

Once you add the code you can run your lambda function. To verify check the logs and see if it is printing out the correct…

--

--

Published in Bits and Pieces

Insightful articles, step-by-step tutorials, and the latest news on full-stack composable software development

Written by Shadid Haque

Software Craftsman | Entrepreneur | Freelancer. Always on the look for opportunities to make the world a little bit better with technology.

No responses yet

Write a response