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
Python API for working with RESQML models

resqpy: Python API for working with RESQML models Introduction resqpy is a pure python package which provides a programming interface (API) for readin

BP 44 Dec 14, 2022
Upload-Instagram - Auto Uploading Instagram Bot

###Instagram Uploading Bot### Download Python and Chrome browser pip install -r

byeonggeon sim 1 Feb 13, 2022
A free and open-source SMS/Call bombing application

TBOMB V0.1 A free and open-source SMS/Call bombing application NOTE: For Termux To use the bomber type the following commands in Termux: pkg install g

ᴀɴᴋɪᴛ ᴋᴜᴍᴀʀ 2 Dec 07, 2021
Telegram 隨機色圖,支援每日自動爬取

Telegram 隨機色圖機器人 使用此原始碼的Bot 開放的隨機色圖機器人: @katonei_bot 已實現的功能 爬取每日R18排行榜 不夠色!再來一張 Tag 索引,指定Tag色圖 將爬取到的色圖轉為 WebP 格式儲存,節省空間 需要注意的事件 好久之前的怪東西,代碼質量不保證 請在使用A

cluckbird 15 Oct 18, 2021
Python Tool To Get The Date That Your Account Joined Instagram

Date-Joined-Insta Python Tool To Get The Date That Your Account Joined Instagram You Dont Need To Login Just Enter The UserName If Id Did Not Work Ins

A B D U L L A H . 1 Dec 21, 2021
Latest Open Source Code for Playing Music in Telegram Video Chat. Made with Pyrogram and Pytgcalls 💖

MusicPlayer_TG Latest Open Source Code for Playing Music in Telegram Video Chat. Made with Pyrogram and Pytgcalls 💖 Requirements 📝 FFmpeg NodeJS nod

Abhijith Sudhakaran 2 Feb 04, 2022
Red-mail - Advanced email sending library for Python

Red Mail Next generation email sender What is it? Red Mail is an advanced email

Mikael Koli 313 Jan 08, 2023
ApiMoedas - This API is a extesion of API

🪙 Api Moeda 🪙 Este projeto é uma extensão da API Awesome API. Basicamente, ele mostra todas as moedas que a Awesome API tem e todas as suas conversõ

Abel 4 May 29, 2022
Shows VRML team stats of all players in your pubs

VRML Team Stat Searcher Displays Team Name, Team Rank (Worldwide), and tier of all the players in your pubs. GUI WIP: Username search works & pub name

Hamish 2 Dec 22, 2022
Cloudkeeper is “housekeeping for clouds” - find leaky resources, manage quota limits, detect drift and clean up.

Cloudkeeper Housekeeping for Clouds! Table of contents Overview Docker based quick start Cloning this repository Component list Contact License Overvi

Some Engineering 1.2k Jan 03, 2023
Discord E-Store Bot

A delivery bot for Discord, works like Amazon where real users can pack & deliver orders in different servers!

Amit Pathak 2 Jan 28, 2022
simple discord token grabber with webhook hiding feature.

Token Grabber A simple Discord token grabber with base64 webhook encoding, it uses pastebin as a database to get webhook, so next time u dont get your

0 Dec 01, 2021
Make WhatsApp ChatBot and use WhatsApp API to send the WhatsApp messages in python .

Ultramsg.com WhatsApp Bot using WhatsApp API and ultramsg Demo WhatsApp API ChatBot using Ultramsg API with python. Opportunities and tasks: The outpu

Ultramsg 64 Dec 29, 2022
A python script to extract information from a Microsoft Remote Desktop Web Access (RDWA) application

This python script allow to extract various information from a Microsoft Remote Desktop Web Access (RDWA) application, such as the FQDN of the remote server, the internal AD domain name (from the FQD

Podalirius 60 Dec 09, 2022
Wedding website for July 2022.

Capstone Project: a real wedding website! User Stories A user should be able to signup for the website A user should be able to login to the website i

1 Nov 04, 2021
A fork of discord.py meant to replace it

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

Texus 1 Nov 18, 2021
Maubot azuracast - A maubot to fetch data from your radio station

Maubot Azuracast A maubot to fetch data from your radio station Setup Configure

3 Mar 14, 2022
Robocord is a bot created for the Pycord community.

Robocord is a bot created for the community of the Pycord Server. Just a bot created for Pycord Server. You can start pull requests, I will check it and if its good I will add it to the bot. 👍

Bruce 7 Jun 26, 2022
Verkehrsunfälle in Deutschland, aufgeschlüsselt nach Verkehrsmittel des Hauptverursachers und Nebenverursachers

How-To Einfach ./main.py ausführen mit der Statistik-Datei aus dem Ordner "Unfälle_mit_mehreren_Beteiligten" als erstem Argument. Requirements python,

4 Oct 12, 2022
Pixiv 爬虫,使用 Python 实现。支持批量下载、上传到图床。

用 Python 实现的 Pixiv 爬虫,支持批量下载和上传。 随机图片 API: https://loliapi.ml/ Deploy Github Action 集成部署 建议使用本方法部署,相较于本地部署,无需搭建环境,全程在线上完成。并且使用国外服务器下载、上传,网络更加通畅。 Fork

18 Feb 26, 2022