Skip to content

This project provides a working, open source based, Serverless cron jobs Python code including DEPLOYMENT code with CDK and a pipeline.

License

Notifications You must be signed in to change notification settings

ran-isenberg/aws-serverless-cron-template

Repository files navigation

AWS Serverless Cron Job Template (Python)

license PythonSupport version github-star-badge issues

alt text

This project provides a working, open source based, Serverless cron jobs Python code including DEPLOYMENT code with CDK and a pipeline.

The project provides the following cron jobs:

  1. AWS EventBridge rule cron job that triggers a lambda every X minutes
  2. AWS EventBridge rule cron job that triggers a step function once a day at a specific time
  3. AWS EventBridge scheduler cron job that triggers a lambda once a day

The AWS Lambda function use a logger, metrics, tracing, environment variables parsing and input validation best practices.

This project can serve as a template for new Serverless cron jobs or a as a reference. - CDK deployment code, pipeline and handler are covered.

Blogs website

Contact details | [email protected]

Features

  • Python Serverless service with a recommended file structure.
  • CDK infrastructure with infrastructure tests and security tests.
  • CI/CD pipelines based on Github actions that deploys to AWS with python linters, static code analysis, complexity checks and style formatters.
  • 3 different Serverless cron jobs including the new AWS EventBridge scheduler
  • Unit, integration and E2E test folders ready for implementation.

Serverless Best Practices

The AWS Lambda handler will implement multiple best practice utilities.

Each utility is implemented when a new blog post is published about that utility.

The utilities cover multiple aspect of a production-ready service, including:

Getting started

Prerequisites

  • Docker - install Docker. Required for the Lambda layer packaging process.
  • AWS CDK - Required for synth & deploying the AWS Cloudformation stack.
  • Python 10
  • poetry - Make sure to run poetry config --local virtualenvs.in-project true so all dependencies are installed in the project '.venv' folder.
  • For Windows based machines, use the Makefile_windows version (rename to Makefile). Default Makefile is for Mac/Linux.

Creating a Developer Environment

  1. Run make dev
  2. Run poetry install

Deploy CDK

Create a cloudformation stack by running make deploy.

Deleting the stack

CDK destroy can be run with make destroy.

Preparing Code for PR

Run make pr. This command will run all the required checks, pre commit hooks, linters, code formats, flake8 and tests, so you can be sure GitHub's pipeline will pass.

The command auto fixes errors in the code for you.

If there's an error in the pre-commit stage, it gets auto fixed. However, are required to run make pr again so it continues to the next stages.

Be sure to commit all the changes that make pr does for you.

Building dev/lambda_requirements.txt

lambda_requirements.txt

CDK requires a requirements.txt in order to create a zip file with the Lambda layer dependencies. It's based on the project's poetry.lock file.

``make deploy` command will generate it automatically for you.

dev_requirements.txt

This file is used during GitHub CI to install all the required Python libraries without using poetry.

File contents are created out of the Pipfile.lock.

make deploy make deps commands generate it automatically.

Code Contributions

Code contributions are welcomed. Read this guide.

Code of Conduct

Read our code of conduct here.

Connect

Credits

License

This library is licensed under the MIT License. See the LICENSE file.

About

This project provides a working, open source based, Serverless cron jobs Python code including DEPLOYMENT code with CDK and a pipeline.

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published