/template-serverless-lambda-python

Template com exemplos de boilerplates para a criação de aplicações para lambda com Python.

Primary LanguageShellMIT LicenseMIT

template-serverless-lambda-python

This project contains isolated examples of AWS Lambda Services as well this provide a stack example. linting: pylint PEP8 Quality Gate Status Coverage Reliability Rating

Service Architecture

Diagrams with application usage of this architecture.

More details here.

Cloud Architecture

Example of the architecture running on AWS Cloud.

Service-Arch

Docker Architecture

Example of the architecture running with docker. Docker-Service-Arch

General Service Routes Architecture

Example of OpenApi documentation. Swagger

Route list:

GET / - Root
GET /docs - Swagger docs
GET /alive - Health Check
GET /v1/event/<event_type> - Event List
POST /v1/event/<event_type> - Create Event

Prerequisites

  • Python >=3.6
  • docker
  • docker-compose
  • python-dotenv
  • jsonformatter
  • requests
  • pytz
  • redis
  • pyyaml
  • apispec
  • marshmallow
  • Flask

Features

  • Docker-compose
  • Localstack
  • SQS Integration
  • Flask
  • MySQL
  • Redis

Build environment script workflow

Example of the workflow to create the environment. Runenv-Workflow

Single project examples

You can find light examples:

You can find complex examples:

Details about requirements files

requirements.txt

Collection of common application modules, light modules.

requirements-vendor.txt

Collection of specific application modules, heavy modules that can be converted to layers if necessary.

requirements-tests.txt

Collection of specific test application modules.

Installation

Installing AWS CLI

Documentation: https://docs.aws.amazon.com/pt_br/cli/latest/userguide/install-cliv2.html

Execute the follow command:

apt install python38-env
apt install awscli
apt install zip
app install pip

Execute the follow command:

aws configure

Installing python venv support

Execute the follow command:

apt install python38-env

Creating the Docker Network

To execute the creation of the Docker network, execute the follow command:

./scripts/docker/create-network.sh

Running Locally

To create the venv and install the modules execute:

./scripts/venv.sh

Running via docker

To execute the build:

./scripts/runenv.sh --build

Execute the follow command:

./scripts/runenv.sh

Recovering the environment in error cases

Execute the follow command:

./scripts/fixenv.sh

Automation scripts information

Bellow we describe the usage of the automation scripts. These kebab case scripts helps the developer in general tasks.

General scripts

Kebab case script to help the developer in general tasks.

Script Description Context
autopep8.sh Execute the code-lint for pep8 Codelint
boot.sh Boot the application during de container execution Local boot
boot-db.sh Boot the data for the database Local boot
boot-queues.sh Boot the queues of the application in the localstack Local boot
boot-validate-connection.sh Check if localstack is ready to connect Local boot
clean-env.sh Clean the ./vendor folder Local install
fixenv.sh In some cases where the network are deleted, you can fix the container references Local install
install.sh Script to install the dependencies Local install
install-local.sh Script to install the dependencies in the ./vendor folder Local install
openapi.sh Script to generate the openapi.yaml CI/CD pipeline
preenv.sh Script to execute the pre build commands Local boot
pylint.sh Script to execute the pylint analysis Local development
runenv.sh Script to start the project locally Local development
testenv.sh Script to run the environment with focus in the component tests Local development
venv.sh Script to install the dependencies in the venv folder Local install
venv-exec.sh Script to execute scripts to install content inside the venv Local install
zip.sh Generate a zip file with the application content Other

Docker scripts

Helper scripts to do tasks for docker context;

Flask scripts

Helper scripts to run flask locally, not inside a docker container;

Localstack scripts

Helper scripts to run commands over Localstack resources like S3, SQS, Lambda, etc;

Migrations scripts

Helper scripts to execute migrations;

OpenApi scripts

Helper scripts to generate openapi schemas and specifications;

Tests scripts

Helper scripts to execute tests and generate reports;

Samples

See the project samples in this folder here.

Localstack Scripts tips

Lambdas

List functions:

./scripts/localstack/lambda/list-function.sh 

Invoke lambda_api:

 ./scripts/localstack/lambda/invoke-api-function.sh lambda_api
 

Invoke lambda_sqs:

 ./scripts/localstack/lambda/invoke-sqs-function.sh lambda_sqs
 

License

See the license: LICENSE.md.

Contributions