1 réponse
- Le plus récent
- Le plus de votes
- La plupart des commentaires
0
Hi.
I'm using handler
for the entry point function name to avoid confusion in the example below.
This is my folder structure:
Dockerfile
:
FROM public.ecr.aws/lambda/python:3.11 COPY project_folder/ requirements.txt ./ RUN pip install -r requirements.txt CMD ["lambda_handler.handler"]
project_folder/modules/__init__.py
is empty. See Python packages documentation for more details why you will need it.
project_folder/modules/module1.py
:
from utils.function_1 import get_python_version def module_say_hello(): return "I'm using " + get_python_version() + "!"
project_folder/utils/function_1.py
:
import sys def get_python_version(): return 'Python' + sys.version + '!'
project_folder/lambda_handler.py
:
from modules.module1 import module_say_hello def handler(event, context): return module_say_hello()
template.yaml
- SAM template for test deployment to an AWS account:
AWSTemplateFormatVersion: 2010-09-09 Transform: AWS::Serverless-2016-10-31 Resources: PythonDockerImageFunction: Type: AWS::Serverless::Function Properties: PackageType: Image MemorySize: 2048 Timeout: 900 Metadata: DockerContext: ./ Dockerfile: Dockerfile
Test invoke with AWS CLI:
Additional references:
- Deploy Python Lambda functions with container images
- Using container image support for AWS Lambda with AWS SAM
Best regards,
répondu il y a un mois
Contenus pertinents
- demandé il y a un an
- demandé il y a un an
- demandé il y a un an
- AWS OFFICIELA mis à jour il y a 2 ans
- AWS OFFICIELA mis à jour il y a 3 ans
- AWS OFFICIELA mis à jour il y a un an
Hi Dmitry, thank you for the answer. Unfortunately, no. I have the correct def lambda_handler correctly defined. But in this scenario, if you add a second folder modules/ parallel to utils/ and import something from utils in modules/module_1.py, how would that look?
Updated response with multiple folders.