Skip to content

e-mit/aws-lambda-db

Repository files navigation

AWS Lambda DB

local tests coverage flake8 mypy pycodestyle pydocstyle pylint pyright bandit

Creates an AWS Lambda function which receives data from a AWS SQS queue and stores it in an SQL database.

This project uses Pydantic, SQLAlchemy, SQLModel, psycopg2. AWS is configured with the CLI and CloudFormation/SAM template.

See also

Readme Contents

Testing

Tests and linting checks run via GitHub actions after each push. Tests can be run locally (no interaction with AWS), or with AWS (cloud tests).

Local tests

  1. Optional: provide a PostgreSQL database server for testing, else the tests will use SQLite only.
    • The following environment variables must be set before running the tests: TEST_DB_PORT, TEST_DB_USER, TEST_DB_NAME, TEST_DB_HOST, TEST_DB_PASSWORD, TEST_DB_DIALECT_DRIVER
    • The database named TEST_DB_NAME must already exist.
    • Only TEST_DB_DIALECT_DRIVER='postgresql+psycopg2' is supported.
  2. Run all tests and linting with test.sh

Cloud tests

TODO

Deployment

  1. Provide values for the environment variables listed in config.sh
  2. Execute script setup.sh. This will create the resources and start the lambda. A file "id.txt" is created which stores a random number used for uniqueness.
  3. Change log level using: ./create.sh loglevel <log level string e.g. DEBUG>
  4. Stop the lambda and delete all resources using: ./create.sh clean

Development

After deploying the stack, the lambda code and the packaged Python library dependencies can be updated independently, and rapidly, using the following commands:

  • Lambda function update: ./create.sh update_function
  • Python packages update: ./create.sh update_layer

About

Create an AWS Lambda to store data from an AWS SQS queue in an SQL database

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors