aws-lambda-scheduler lets you call any existing AWS Lambda Function you have in a future time.

Overview

aws-lambda-scheduler

aws-lambda-scheduler lets you call any existing AWS Lambda Function you have in the future.

This functionality is achieved by dynamically managing the EventBridge Rules.

aws-lambda-scheduler also has optimizations you can configure and extend yourself. AWS allows maximum of 300 EventBridge rules in a region. If you are expecting to create more than 300 rules, check out Optimizations section below.

Example Usage

When you set up the aws-lambda-scheduler in your AWS environment, you can simply call it with a json data like this:

{
    "datetime_utc": "2030-12-30 20:20:20",
    "lambda_function": "arn:aws:lambda:...........",
    "data": {
        "any": "json",
        "is": "allowed"
    }
}

aws-lambda-scheduler will create a EventBridge rule, and AWS will run the specified lambda_function at the datetime_utc with the given data.

It's that simple. Just remember to convert your datetime to UTC+0 timezone. That's the timezone supported by EventBridge Rules.

Installation

  1. Create a IAM Role with AWS managed AmazonEventBridgeFullAccess and AWSLambdaBasicExecutionRole Roles.
  2. Create a Lambda Function with Python runtime and attach the role you've created to it.
  3. Upload the aws-lambda-scheduler.zip file to your Lambda Function.

How it works

EventBridge Rules are basically cron jobs of AWS. EventBridge Rules must have a schedule, data, and minimum of one target -- in this case the target is a lambda function.

Rules schedule can be fixed rate of minutes, or a cron job schedule expression. aws-lambda-scheduler takes advantage of cronjob schedule expression and creates a Rule that will run only one time.

what happens on runtime

  1. aws-lambda-scheduler will create a EventBridge Rule with the date of datetime_utc, target of lambda_function and targets Constant Json Data being data.
  2. aws-lambda-scheduler will delete the expired EventBridge Rules it previously created.

Basic Configuration

Environment Variable Default Value Description
RULE_PREFIX AUTO_ EventBridge Rule names will be prefixed with this value. Please be careful to have this value constant from the start or expired rule deletion will not function properly as it depends on the prefixes.

Optimizations

aws-lambda-scheduler optimizations can be enabled if the specified lambda invocation times do not have to be punctual.

These optimizations lets you work around the maximum of 300 EventBridge Rules limitation. You can always request a quota increase for EventBridge Rules if these optimizations are not enough for your needs or if you need to be definitely punctual with your lambda calls.

Lets examine the EventBridge Rule limitations before diving into the optimization options.

About EventBridge Rules

EventBridge Rules has to have:

  1. schedule expression (cronjob schedule expression)
  2. target (lambda function)
  3. json data to call the lambda with
  • EventBridge lets you create maximum of 300 Rules per region.
  • EventBridge lets you define maximum of 5 targets per Rule, and targets will be invoked concurrently.

Optimization Configuration Overview

Environment Variable Default Value Optimized Values
ALLOWED_T_MINUS_MINUTES None You specify. Setting this value to any integer will enable optimizations.
RULE_TARGET_ADDING_STRATEGY CONCURRENT_LAMBDA_TARGETS INPUT_CONCATENATOR
INPUT_CONCATENATOR_MODULE_NAME input_concatenators You specify.
INPUT_CONCATENATOR_CLASS_NAME None You have to extend a new class.

config: ALLOWED_T_MINUS_MINUTES

Environment variable ALLOWED_T_MINUS_MINUTES defaults to nothing. If you set it as an environment variable, optimizations are enabled for aws-lambda-scheduler.

Let's say you have called the aws-lambda-scheduler and created a rule.

Rule Name Target Data Detail
AUTO_2030-12-30--20-20 test-lambda {"data":"first-rule"} Note: Rule names are consisted of RULE_PREFIX and datetime its going to run.

If you were to create another rule that would run 5 minutes after the previously created rule, without the optimizations enabled, aws-lambda-scheduler would create a new Rule for it.

Rule Name Target Data Detail
AUTO_2030-12-30--20-20 test-lambda {"data":"first-rule"}
AUTO_2030-12-30--20-25 test-lambda {"data":"second-rule"}

When ALLOWED_T_MINUS_MINUTES is set to an integer, aws-lambda-scheduler will look for a Rule with its date just before ALLOWED_T_MINUS_MINUTES in minutes. If there is a rule close-by, it will just add a new target to the existing rule.

Lets say ALLOWED_T_MINUS_MINUTES is set to 6 and we are adding rules that are 5 minutes apart.

Rule Name Target Data Detail
AUTO_2030-12-30--20-20 test-lambda {"data":"first-rule"} first rule is created
AUTO_2030-12-30--20-20 test-lambda {"data":"second-rule"} second rule is appended to first rule with a new target. It would've been AUTO_2030-12-30--20-25 if the optimizations weren't enabled.
AUTO_2030-12-30--20-30 test-lambda {"data":"third-rule"} There's 10 minutes of difference, so it's created as a new rule.

Great, we've reduced our number of Rules. But this solution creates another problem: what happens if there is more than 5 targets per rule?

Simply, aws-lambda-scheduler will raise an exception.

If you think you will have more than 5 targets per Rule, please continue with the other optimizations below.

Possible solution: We can combine the inputs of the same Lambda targets. This solution would require to implement two things:

  1. a way to combine target lambdas json data (combining all the inputs of all targets)
  2. Target lambda should be able to process combined data

Other optimizations can help us with these newly emerged problems. Lets continue.

config: RULE_TARGET_ADDING_STRATEGY

We know that we can't add more than 5 targets to a Rule.

Environment variable RULE_TARGET_ADDING_STRATEGY defaults to CONCURRENT_LAMBDA_TARGETS. With this configuration aws-lambda-scheduler will create more targets when we are appending an existing Rule.

Other possible value for RULE_TARGET_ADDING_STRATEGY is INPUT_CONCATENATOR.

Setting up the INPUT_CONCATENATOR configuration basically lets you combine two different input json data together for the same lambda targets. And you can implement your logic of input concatenation by extending the input_concatenators.EventBridgeInputConcatenator abstract class.

You only have to implement the following function and set the environment variables accordingly.

def concatenate_inputs(self, existing_data, new_data):
    pass

There's also a ready-to-use implementation of the EventBridgeInputConcatenator called EventBridgeSingleArrayInput.

EventBridgeSingleArrayInput is developed to extend array inputs with the same keys of the json input. You can read more about how it works in the class comments.

Setting INPUT_CONCATENATOR value requires two other variables present in the environment variables: INPUT_CONCATENATOR_MODULE_NAME and INPUT_CONCATENATOR_CLASS_NAME.

Config Detail Values for below example
INPUT_CONCATENATOR_MODULE_NAME filename of your implementation of the abstract class. input_concatenators
INPUT_CONCATENATOR_CLASS_NAME name of your implementation of abstact class EventBridgeSingleArrayInput

Lets say we've added to rules for two different lambda targets for the same date.

Rule Name Target Data Detail
AUTO_2030-12-30--20-20 test-lambda {"data":"first-rule"} first target is for test-lambda is created
AUTO_2030-12-30--20-20 other-test-lambda {"data":"different-rule"} first target for other-test-lambda is created

Lets add a new target for test-lambda with the same datetime_utc. The third target looks like this before creation:

Rule Name Target Data Detail
AUTO_2030-12-30--20-20 test-lambda {"data":"third-rule"} we have our INPUT_CONCATENATOR optimization enabled, and we are about to add a new target to the same rule.

When we run aws-lambda-scheduler the rules get updated as this:

Rule Name Target Data Detail
AUTO_2030-12-30--20-20 test-lambda {"data":["first-rule", "third-rule"]} EventBridgeSingleArrayInput made a list of the same keys available in the json input of the same target.
AUTO_2030-12-30--20-20 other-test-lambda {"data":"different-rule"} remains the same.

In summary, we wanted to add 3 targets for the same rule:

  • different lambda targets registered as new target for the same rule
  • same lambda targets got its data updated, and no new target or rule is created. Input combination logic is defined by the EventBridgeSingleArrayInput. You can implement your own class to count for different kinds of input concatenations for your needs.
Owner
Oğuzhan Yılmaz
Oğuzhan Yılmaz
A supabase client for python

supabase-client A Supabase client for Python. This mirrors the design of supabase-js Full documentation: https://keosariel.github.io/2021/08/08/supaba

kenneth gabriel 11 Dec 19, 2022
Running Performance Calculator

Running Performance Calculator 👉 Have you ever wondered if you ran 10km at 2000

Davide Liu 6 Oct 26, 2022
This bot will pull a stream of tweets based on rules you set and automatically reply to them.

Twitter reply bot This bot will pull a stream of tweets based on rules you set and automatically reply to them. I built this bot in order to help comb

Brains 1 Feb 13, 2022
Reverse engineered connection to the TradingView ticker in Python

Tradingview-ticker Reverse engineered connection to the TradingView ticker in Python. Makes a websocket connection to the Tradeview website and receiv

Aaron 20 Dec 02, 2022
Discord bot ( discord.py ), uses pandas library from python for data-management.

Discord_bot A Best and the most easy-to-use Discord bot !! Some simple basic auto moderations, Chat functions. It includes a game similar to Casino, g

Jaitej 4 Aug 30, 2022
Lazy airdrop based on private temporary ids

LobsterDAO This uses a modified MerkleDistributor, which allows to issue a lazy airdrop using temporary IDs. In this example it uses Telegram chat_id

41 Sep 10, 2022
A python library built on the API of the coderHub.sa, which helps you to fetch the challenges and more

coderHub A python library built on the API of the coderHub.sa, which helps you to fetch the challenges and more Installation • Features • Usage • Lice

TheAwiteb 5 Nov 04, 2022
A pypi package that helps in generating discord bots.

A pypi package that helps in generating discord bots.

PineCode Corp 3 Nov 17, 2021
This repo provides the source code for "Cross-Domain Adaptive Teacher for Object Detection".

Cross-Domain Adaptive Teacher for Object Detection This is the PyTorch implementation of our paper: Cross-Domain Adaptive Teacher for Object Detection

Meta Research 91 Dec 12, 2022
A maintained fork of Danny's discord.py

Nextcord A modern, easy-to-use, feature-rich, and async-ready API wrapper for Discord written in Python. Fork notice This is a fork of discord.py, whi

977 Jan 05, 2023
Python Library to Extract youtube video Tags without Youtube API

YoutubeTags Python Library to Extract youtube video Tags without Youtube API Installation pip install YoutubeTags Example import YoutubeTags from Yout

Nuhman Pk 17 Nov 12, 2022
A modern,feature-rich, and async ready API wrapper for Discord written in Python

discord.io A modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python. Key Features Modern Pythonic API using asyn

Vincent 18 Jan 02, 2023
This is a translator that i made by myself in python with the 'googletrans' library

Translator-Python This is a translator that i made by myself in python with the 'googletrans' library This application completely made in python allow

Thadeuks 2 Jun 17, 2022
Instagram-follower-bot - An Instagram follower bot written in Python

Instagram Follower Bot An Instagram follower bot written in Python. The bot follows the follower of which account you want. e.g. (You want to follow @

Aytaç Kaşoğlu 1 Dec 31, 2021
Análise de dados abertos do programa Taxigov.

Análise de dados do Taxigov Este repositório contém os cadernos Jupyter usados no projeto de análise de dados do Taxigov. Conjunto de dados O conjunto

Augusto Herrmann 1 Jan 10, 2022
The Bot provide Hadith API and fetch content via api.hadith.sutanlab.id

Bot Hadith-API on Telegram The Bot provide Hadith API and fetch content via api.hadith.sutanlab.id Built With Python Asynchronous HTTP protocol client

xMan 12 Feb 19, 2022
Develop and deploy applications with the Ionburst Cloud Python SDK.

Ionburst SDK for Python The Ionburst SDK for Python enables developers to easily integrate with Ionburst Cloud, building in ultra-secure and private o

Ionburst Cloud 3 Mar 06, 2022
GitHub Actions Docker training

GitHub-Actions-Docker-training Training exercise repository for GitHub Actions using a docker base. This repository should be cloned and used for trai

GitHub School 1 Jan 21, 2022
Moderation By Pokemon Bot (Discord)

Moderation Bot By Pokémon Bot (Discord) Official Moderation Bot for Pokemon Bot functional and based in the Discord Server, the bot is written in Pyth

Aakash Manoj Agrawal 6 Jan 04, 2022
A Telegram bot to index Chinese and Japanese group contents, works with @lilydjwg/luoxu.

luoxu-bot luoxu-bot 是类似于 luoxu-web 的 CJK 友好的 Telegram Bot,依赖于 luoxu 所创建的后端。 测试环境 Python 3.7.9 pip 21.1.2 开发中使用到的 Telethon 需要 Python 3+ 配置 前往 luoxu 根据相

TigerBeanst 10 Nov 18, 2022