Код: Выделить всё
{
"errorMessage": "Unable to import app.app", "errorType":
"Exception", "requestId": "", "stackTrace": [
File "/var/lang/lib/python3.12/importlib/__init__.py", line 90,
in import_module
return _bootstrap._gcd_import(name[level:], package, level),
File "", line 1387,
in _gcd_import,
File "", line 1360,
in _find_and_load,
File "", line 1331,
in _find_and_load_unlocked,
File "", line 935,
in _load_unlocked",
File "", line 995,
in exec_module",
File "", line 488,
in _call_with_frames_removed",
File "/var/task/wsgi_handler.py", line 115,
in
wsgi_app = import_app(config)",
File "/var/task/wsgi_handler.py", line 48,
in import_app
raise Exception("Unable to import {}".format(config["app"]))"
] }
< strong>serverless.yml
Код: Выделить всё
service: email-sender
provider:
name: aws
runtime: python3.12
region: ap-south-1
functions:
api:
handler: wsgi_handler.handler
events:
- http:
path: /
method: post
- http:
path: /{proxy+}
method: post
plugins:
- serverless-wsgi
- serverless-python-requirements
- serverless-plugin-common-excludes
- serverless-plugin-include-dependencies
custom:
wsgi:
app: app.app
pythonRequirements:
dockerizePip: true # Use Docker to install dependencies
layer: true # Create a Lambda Layer for the requirements
zip: true # Zip the requirements to reduce the deployment package size
commonExcludes:
- '**/tests/**'
Код: Выделить всё
FROM public.ecr.aws/lambda/python:3.9
COPY app.py ./
COPY wsgi_handler.py ./
COPY requirements.txt ./
RUN pip install -r requirements.txt
ENV FLASK_APP=app.py
CMD ["wsgi_handler.handler"]
Код: Выделить всё
import os
from importlib import import_module
def import_app(config):
module_name, app_name = config['app'].rsplit('.', 1)
module = import_module(module_name)
return getattr(module, app_name)
config = {
'app': 'app.app' # Adjust this path if necessary
}
wsgi_app = import_app(config)
def handler(event, context):
return wsgi_app(event, context)
Подробнее здесь: https://stackoverflow.com/questions/786 ... -and-flask