Here is my serverless.yml
file:
org: jmgilman
app: fapi
service: fapi
frameworkVersion: '2 || 3'
provider:
name: aws
runtime: python3.8
lambdaHashingVersion: '20201221'
region: us-west-2
functions:
balance:
handler: balance.main
events:
- httpApi:
path: /
method: get
plugins:
- serverless-python-requirements
custom:
pythonRequirements:
slim: true
layer: true
dockerizePip: true
My dependencies are handled by Poetry:
[tool.poetry]
name = "fapi"
version = "0.1.0"
description = ""
[tool.poetry.dependencies]
python = "^3.8"
beancount = "^2.3.4"
boto3 = "^1.20.30"
[tool.poetry.dev-dependencies]
black = "^21.12b0"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
The top of my balance.py
file:
import boto3
import json
import os
from beancount import loader
from beancount.core import realization
from pathlib import Path
When I run the function I get the following error:
[ERROR] ModuleNotFoundError: No module named 'beancount'
The deploy process seems to be working as expected with the serverless-python-requirements
plugin doing the necessary work to package the dependencies with the function.
$ serverless deploy
Serverless: Running "serverless" installed locally (in service node_modules)
Serverless: Generating requirements.txt from pyproject.toml...
Serverless: Parsed requirements.txt from pyproject.toml in /Users/josh/code/fapi/.serverless/requirements.txt...
Serverless: Using static cache of requirements found at /Users/josh/Library/Caches/serverless-python-requirements/7b6085c32db879837c55e163f2b383174b0a9de7d5bc0af9a340bbc9c8f23fc9_x86_64_slspyc ...
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Packaging Python Requirements Lambda Layer...
Serverless: Ensuring that deployment bucket exists
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service fapi.zip file to S3 (51.38 MB)...
Serverless: Uploading service pythonRequirements.zip file to S3 (34 MB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
............
Serverless: Stack update finished...
I’ve looked at a dozen or so tutorials and SO answers and nothing is sticking out that I’ve done wrong here. Any idea why the function can’t find the beancount
dependency ?