awslabs / aws-lambda-web-adapter

Run web applications on AWS Lambda
Apache License 2.0
1.92k stars 115 forks source link

Fast API run script Excludes LAMBDA_RUNTIME_DIR from Search Path #453

Closed renjiexu-amzn closed 6 months ago

renjiexu-amzn commented 6 months ago

e.g., https://github.com/awslabs/aws-lambda-web-adapter/blob/main/examples/fastapi-response-streaming-zip/app/run.sh#L4 is setting PYTHONPATH to LAMBDA_TASK_ROOT, which led to the search path (more background in Working with .zip file archives for Python Lambda functions) becoming ['', '/var/task', '/var/task', '/var/lang/lib/python38.zip', '/var/lang/lib/python3.8', '/var/lang/lib/python3.8/lib-dynload', '/var/lang/lib/python3.8/site-packages']. The second and third element are duplicate. And even worse, $LAMBDA_RUNTIME_DIR isn't in the search path any more, which led to the user won't be able to use the bundled modules under $LAMBDA_RUNTIME_DIR (e.g., boto3 SDK, which a user may not bundle into their zip archive to stay under the unzipped size limit).

bnusunny commented 6 months ago

Thanks for reporting this issue. This affects python runtimes below 3.11. From 3.11 and above versions, AWS SDK is installed in /var/lang/lib/python3.x/site-packages.