-
Hi! I having some issues trying to run aws-lambda-web-adapter projects with a common layer with all the fast API dependencies. Template for lambda layer: FastApiLayer:
Type: AWS::Serverless::LayerVersion
Properties:
ContentUri: FastApiLayer/
CompatibleRuntimes:
- python3.11
Metadata:
BuildMethod: python3.11
BuildArchitecture: x86_64 Template for lambda function: FlaskFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: app/
Handler: run.sh
Runtime: python3.11
MemorySize: 128
Environment:
Variables:
AWS_LAMBDA_EXEC_WRAPPER: /opt/bootstrap
PORT: 8000
Layers:
- !Sub arn:aws:lambda:${AWS::Region}:753240598075:layer:LambdaAdapterLayerX86:20
- Fn::ImportValue: "backend-layers-FastApiLayer" requirements.txt for lambda layer
And finally the run.sh #!/bin/bash
exec python -m uvicorn --port=$PORT app:app I get the following error Something is different in the way that SAM deploy the package with and without the lambda layer. I have unziped the layer, and the original function (with the dependencies, not the layer) and I can't see the diff except for the folder structure. original funcion:
Lambda layer:
Y need to change anything in the run.sh file to work with uvicorn inside a lambda layer? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Check out the run.sh in fastapi-zip example. You need to configure a few environment variables. |
Beta Was this translation helpful? Give feedback.
-
/opt/python must to be added to PYTHONPATH #!/bin/bash
PATH=$PATH:$LAMBDA_TASK_ROOT/bin PYTHONPATH=$LAMBDA_TASK_ROOT:/opt/python exec python -m uvicorn --port=$PORT app:app |
Beta Was this translation helpful? Give feedback.
Check out the run.sh in fastapi-zip example. You need to configure a few environment variables.