Skip to content

Commit

Permalink
Updated example
Browse files Browse the repository at this point in the history
  • Loading branch information
ulises-jeremias committed Aug 29, 2023
1 parent 944f39c commit 2bc4a90
Show file tree
Hide file tree
Showing 14 changed files with 4,638 additions and 10,500 deletions.
8 changes: 8 additions & 0 deletions examples/serverless-python-fastapi/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[flake8]
ignore = E203, E266, E501, W503, F403, F401
max-line-length = 89
max-complexity = 18
select = B,C,E,F,W,T4,B9
require-plugins =
flake8-bugbear
flake8-black
154 changes: 139 additions & 15 deletions examples/serverless-python-fastapi/.gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,146 @@
# package directories
node_modules
.build
##### IDE's #####
# VisualStudioCode
/.vscode/
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
.history

# testing
coverage
# IntelliJ IDEA
.idea/*

temp
dist
.webpack
.webpackCache
##### Database #####
*.accdb
*.db
*.dbf
*.mdb
*.pdb
*.sqlite3

# Serverless directories
.serverless
##### Logs #####
*.log
*.log*

ideas.txt
.DS_Store
.idea/*
##### Python #####
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

*.log
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
bin/

# Environments
Makefile
.env
.env.*
!.env.example.json
!.env.compose.local
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
.flaskenv
pyvenv.cfg

# PyInstaller
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Flask stuff:
instance/
.webassets-cache

# Translations
*.mo
*.pot

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# IPython
profile_default/
ipython_config.py

# PEP 582
__pypackages__/

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# C extensions
*.so

##### Heroku (old) #####
Procfile

###
postgres-calculate/

app/authentication/test_view.py

# Serverless
node_modules/
.serverless/

# wsgi
wsgi_handler.py
serverless_wsgi.py
.serverless-wsgi
7 changes: 7 additions & 0 deletions examples/serverless-python-fastapi/.markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"MD041": false,
"MD042": false,
"MD004": false,
"MD013": false,
"MD033": false
}
2 changes: 1 addition & 1 deletion examples/serverless-python-fastapi/.node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.13.2
v18.17.0
13 changes: 13 additions & 0 deletions examples/serverless-python-fastapi/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/ambv/black
rev: 23.1.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies: [flake8-black, flake8-bugbear]
29 changes: 18 additions & 11 deletions examples/serverless-python-fastapi/README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
# Serverless FastAPI
# Serverless FastAPI example

Serverless Framework + FastAPI example with the following features:

- production ready deployment
- local development out of the box
We use [Serverless](https://www.serverless.com/) to deploy our API to AWS Lambda.

## Requirements

**You’ll need to have Node 16.13.2 or later on your local development machine** (but it’s not required on the server). You can use [fnm](https://github.com/Schniz/fnm) to easily switch Node versions between different projects.
**You’ll need to have Node 18.17.0 or later on your local development machine** (but it’s not required on the server). You can use [fnm](https://github.com/Schniz/fnm) to easily switch Node versions between different projects.

```sh
fnm use
npm install
```

**You'll also need to have Python 3.9 installed on your local development machine**. You can use [pyenv](https://github.com/pyenv/pyenv) to easily switch Python versions between different projects.
**You'll also need to have Python 3.9 installed on your local development machine**. You can use [pyenv](https://github.com/pyenv/pyenv) to easily switch Python versions between different projects. If you are using Windows, you should use [pyenv-win](https://github.com/pyenv-win/pyenv-win).

```sh
pyenv install
pyenv local
```

### Gotchas for Certain Environments

**Depending on your dev environment, it may also be necessary to create and initiate a virtualenv for python**. Do so by running the below commands:

```sh
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt
```

For windows user using WSL2, you may also need to have Docker Desktop installed, running, and with the [WSL2 connection](https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-containers) set up.

## Local Development

In order to develop locally, you'll need to install the dependencies and run the application using Serverless Offline.

### Serverless

#### Install Dependencies
### Install Dependencies

```sh
npm run sls requirements install
```

#### Run the Application
### Run the Application

This repo has a local development set up that uses the file `.env.local` to configure the local environment.
Run the following command to start the local development server:
Expand Down
Loading

0 comments on commit 2bc4a90

Please sign in to comment.