Skip to content

A skeleton project for quickly getting a new Python-based AWS Lambda project started.

License

Notifications You must be signed in to change notification settings

cisagov/skeleton-aws-lambda-python

Repository files navigation

skeleton-aws-lambda-python

GitHub Build Status

This is a generic skeleton project that can be used to quickly get a new cisagov GitHub AWS Lambda project using the Python runtimes started. This skeleton project contains licensing information, as well as pre-commit hooks and GitHub Actions configurations appropriate for the major languages that we use.

Building the base Lambda image

The base Lambda image can be built with the following command:

docker compose build

This base image is used both to build a deployment package and to run the Lambda locally.

Building a deployment package

You can build a deployment zip file to use when creating a new AWS Lambda function with the following command:

docker compose up build_deployment_package

This will output the deployment zip file in the root directory.

Running the Lambda locally

The configuration in this repository allows you run the Lambda locally for testing as long as you do not need explicit permissions for other AWS services. This can be done with the following command:

docker compose up --detach run_lambda_locally

You can then invoke the Lambda using the following:

 curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'

The {} in the command is the invocation event payload to send to the Lambda and would be the value given as the event argument to the handler.

Once you are finished you can stop the detached container with the following command:

docker compose down

How to update Python dependencies

The Python dependencies are maintained using a Pipenv configuration for each supported Python version. Changes to requirements should be made to the respective src/py<Python version>/Pipfile. More information about the Pipfile format can be found here. The accompanying Pipfile.lock files contain the specific dependency versions that will be installed. These files can be updated like so (using the Python 3.9 configuration as an example):

cd src/py3.9
pipenv lock

New Repositories from a Skeleton

Please see our Project Setup guide for step-by-step instructions on how to start a new repository from a skeleton. This will save you time and effort when configuring a new repository!

Contributing

We welcome contributions! Please see CONTRIBUTING.md for details.

License

This project is in the worldwide public domain.

This project is in the public domain within the United States, and copyright and related rights in the work worldwide are waived through the CC0 1.0 Universal public domain dedication.

All contributions to this project will be released under the CC0 dedication. By submitting a pull request, you are agreeing to comply with this waiver of copyright interest.