I'm trying to do my first sam build, following tutorial here: https://iwpnd.pw/articles/2020-01/deploy-fastapi-to-aws-lambda#
My application works with fastapi and is working well.
My template.yaml is like this:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
fastAPI aws lambda example
Resources:
FastapiExampleLambda:
Type: AWS::Serverless::Function
Properties:
Events:
ApiEvent:
Properties:
RestApiId:
Ref: FastapiExampleGateway
Path: /{proxy+}
Method: ANY
Type: Api
FunctionName: fastapi-lambda-example
CodeUri: ./app
Handler: app.main.handler
Runtime: python3.7
Timeout: 300 # timeout of your lambda function
MemorySize: 128 # memory size of your lambda function
Description: fastAPI aws lambda example
# other options, see ->
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-template-anatomy-globals.html#sam-specification-template-anatomy-globals-supported-resources-and-properties
Role: !Sub arn:aws:iam::${AWS::AccountId}:role/fast_api_lambda_role
FastapiExampleGateway:
Type: AWS::Serverless::Api
Properties:
StageName: prod
OpenApiVersion: '3.0.0'
My structure is
/Project/app/app/main.py
requirements is in /Project/app
template.yaml is in /Project
When I do sam build --use-container --debug after a while I got the following error:
Final incompatible: {uvloop==0.14.0(wheel), cryptography==2.8(wheel), websockets==8.1(wheel), pydantic==1.2(wheel)}
Final missing wheels: {uvloop==0.14.0(wheel)}
PythonPipBuilder:ResolveDependencies failed
Traceback (most recent call last):
File "/var/lang/lib/python3.7/site-packages/aws_lambda_builders/workflows/python_pip/actions.py", line 42, in execute
requirements_path=self.manifest_path,
File "/var/lang/lib/python3.7/site-packages/aws_lambda_builders/workflows/python_pip/packager.py", line 137, in build_dependencies
self._dependency_builder.build_site_packages(requirements_path, artifacts_dir_path, scratch_dir_path)
File "/var/lang/lib/python3.7/site-packages/aws_lambda_builders/workflows/python_pip/packager.py", line 201, in build_site_packages
raise MissingDependencyError(packages_without_wheels)
aws_lambda_builders.workflows.python_pip.packager.MissingDependencyError: {uvloop==0.14.0(wheel)}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/lang/lib/python3.7/site-packages/aws_lambda_builders/workflow.py", line 269, in run
action.execute()
File "/var/lang/lib/python3.7/site-packages/aws_lambda_builders/workflows/python_pip/actions.py", line 45, in execute
raise ActionFailedError(str(ex))
aws_lambda_builders.actions.ActionFailedError: {uvloop==0.14.0(wheel)}
Builder workflow failed
Traceback (most recent call last):
File "/var/lang/lib/python3.7/site-packages/aws_lambda_builders/workflows/python_pip/actions.py", line 42, in execute
requirements_path=self.manifest_path,
File "/var/lang/lib/python3.7/site-packages/aws_lambda_builders/workflows/python_pip/packager.py", line 137, in build_dependencies
self._dependency_builder.build_site_packages(requirements_path, artifacts_dir_path, scratch_dir_path)
File "/var/lang/lib/python3.7/site-packages/aws_lambda_builders/workflows/python_pip/packager.py", line 201, in build_site_packages
raise MissingDependencyError(packages_without_wheels)
aws_lambda_builders.workflows.python_pip.packager.MissingDependencyError: {uvloop==0.14.0(wheel)}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/lang/lib/python3.7/site-packages/aws_lambda_builders/workflow.py", line 269, in run
action.execute()
File "/var/lang/lib/python3.7/site-packages/aws_lambda_builders/workflows/python_pip/actions.py", line 45, in execute
raise ActionFailedError(str(ex))
aws_lambda_builders.actions.ActionFailedError: {uvloop==0.14.0(wheel)}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/lang/lib/python3.7/site-packages/aws_lambda_builders/__main__.py", line 126, in main
mode=params.get("mode", None),
File "/var/lang/lib/python3.7/site-packages/aws_lambda_builders/builder.py", line 125, in build
return workflow.run()
File "/var/lang/lib/python3.7/site-packages/aws_lambda_builders/workflow.py", line 76, in wrapper
func(self, *args, **kwargs)
File "/var/lang/lib/python3.7/site-packages/aws_lambda_builders/workflow.py", line 276, in run
raise WorkflowFailedError(workflow_name=self.NAME, action_name=action.NAME, reason=str(ex))
aws_lambda_builders.exceptions.WorkflowFailedError: PythonPipBuilder:ResolveDependencies - {uvloop==0.14.0(wheel)}
Build inside container returned response {"jsonrpc": "2.0", "id": 1, "error": {"code": 400, "message": "PythonPipBuilder:ResolveDependencies - {uvloop==0.14.0(wheel)}"}}
Build Failed
Sending Telemetry: {'metrics': [{'commandRun': {'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'duration': 121098, 'exitReason': 'BuildError', 'exitCode': 1, 'requestId': 'f020dd4f-0ab2-4d35-bb27-50136d7190d9', 'installationId': 'acc6ee82-60bf-4a06-a81c-405c230a0da1', 'sessionId': 'ed7fd895-e84e-4088-81c8-29386e6a31bf', 'executionEnvironment': 'CLI', 'pyversion': '3.7.6', 'samcliVersion': '0.41.0'}}]}
HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Error: PythonPipBuilder:ResolveDependencies - {uvloop==0.14.0(wheel)}
Do you have any idea what is wrong ?
Weird, uvloop does have manylinux wheels: https://pypi.org/project/uvloop/#files so it should get built. Needs some investigation.
One idea, I can suggest is downloading the manylinux wheel directly and placing it in the requirements.txt
I just did pip install wheel like in following answer https://stackoverflow.com/a/58758079 and it resolve the issue.
It might be worth to add wheel package checking before build command execution?
Getting similar issue with:
Error: PythonPipBuilder:ResolveDependencies - {pyrsistent==0.15.7(sdist)}
Using Python 3.6.5, SAM CLI v0.40.0. I tried pip install wheel but that didn't seem to make a difference.
us too
@yeyeric, uvloop is a dependency of uvicorn. It is likely required for you to run and test your application locally, but it is not required to run your fastapi server in the cloud. Remove uvicorn from your requirements.txtand sam build --use-container --debug should complete without that error.
Hello,
Yes confirmed it worked as you said
Thanks
Most helpful comment
us too