Last active
March 8, 2021 17:27
-
-
Save mcclory/e63f97a8bee14b8a6e7e5303f36a3efb to your computer and use it in GitHub Desktop.
Python + Poetry in serverless - A few things to make sure you have in your serverless.yml file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Distribution / packaging | |
.Python | |
.DS_Store | |
env/ | |
build/ | |
develop-eggs/ | |
dist/ | |
downloads/ | |
eggs/ | |
.eggs/ | |
lib/ | |
lib64/ | |
parts/ | |
sdist/ | |
var/ | |
*.egg-info/ | |
.installed.cfg | |
*.egg | |
.venv # venv from poetry w/ | |
# Serverless directories and stuff | |
.serverless | |
_dev | |
requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[virtualenvs] | |
in-project = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
frameworkVersion: '2' | |
custom: | |
pythonRequirements: | |
dockerizePip: non-linux | |
scripts: | |
hooks: | |
'package:initialize': poetry export -f requirements.txt > requirements.txt | |
provider: | |
name: aws | |
runtime: python3.8 | |
lambdaHashingVersion: 20201221 | |
tracing: | |
lambda: true | |
package: | |
# include: | |
# - include-me.py | |
# - include-me-dir/** | |
exclude: | |
- node_modules | |
- .env | |
- package-lock.json | |
- package.json | |
- poetry.toml | |
- poetry.lock | |
- .flake8 | |
- .git | |
- .gitignore | |
- .pylintrc | |
- _data | |
- docker-compose.yml | |
- .github | |
- .pytest_cache | |
- .venv | |
- tests | |
useDotenv: true | |
plugins: | |
- serverless-python-requirements |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So I use Poetry because it's awesome, but the way serverless is setup, it still looks for a good 'ol
requirements.txt
... so... easiest way around this is twofold:custom.scripts.hooks.package:initialize
script to dump out yourrequirements.txt
from your poetry setuprequirements.txt
to your.gitignore
fileI've also thrown in some excludes to make sure my local stuff doesn't overload the lambda env (since there's a 75MB limit)...
Generally... I tend to:
in-project
set totrue
which generates a.venv
directory in the project (I like to keep things together).gitignore
file has some extra stuff in it to prevent uploading common stuff that shouldn't go to the repo (dependencies and such...)