aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Can't build sam with missing wheel for PyYaml

Open NealHumphrey opened this issue 7 years ago • 7 comments

Description

I am trying to use sam build to build my lambda and test it locally with a requirements.txt that includes the awscli. This in turn requires pyyaml. pyyaml is missing a wheel, and when sam tries to resolve this by building from the sdist it can't do it. What appear to be the relevant sections of the build logs are below.

When I omit the awscli dependency, the build succeeds. When I deploy the Lambda to AWS using a cloudformation pipeline, it uses the Pipfile instead of the requirements.txt, and it is able to deploy successfully. But I can't use sam to build and test my lambda locally.

Steps to reproduce

Create a Lambda that includes a dependency of awscli==1.16.155 and/or pyyaml==3.13 and run sam build

Observed result

2019-05-10 10:21:25 Build missing wheels from sdists (C compiling True): {rbt-utilities==0.0.1(sdist), pyyaml==3.13(sdist), article-data==0.0.1(sdist), awscli-wrapper==0.0.1(sdist), vectorizer==0.0.1(sdist), classifier==0.0.1(sdist), binarizer==0.0.1(sdist), nltk==3.4.1(sdist)}
...
2019-05-10 10:21:27 calling pip wheel --no-deps --wheel-dir /var/folders/cs/xfy7j9k12gvc12l0v9tvt0k1l7nvry/T/tmpx8snqxbs /var/folders/cs/xfy7j9k12gvc12l0v9tvt0k1l7nvry/T/tmpx8snqxbs/PyYAML-3.13.tar.gz
...
2019-05-10 10:21:41 compatible after building wheels (no C compiling): {ply==3.11(wheel), html2text==2018.1.9(wheel), requests==2.21.0(wheel), colorama==0.3.9(wheel), psycopg2==2.7.7(wheel), pyasn1==0.4.5(wheel), decorator==4.4.0(wheel), binarizer==0.0.1(wheel), certifi==2019.3.9(wheel), scikit-learn==0.21.0(wheel), scipy==1.2.1(wheel), s3transfer==0.2.0(wheel), python-dateutil==2.8.0(wheel), chardet==3.0.4(wheel), botocore==1.12.145(wheel), scikit-multilearn==0.2.0(wheel), awscli==1.16.155(wheel), boto3==1.9.145(wheel), rbt-utilities==0.0.1(wheel), article-data==0.0.1(wheel), awscli-wrapper==0.0.1(wheel), vectorizer==0.0.1(wheel), classifier==0.0.1(wheel), urllib3==1.24.3(wheel), nltk==3.4.1(wheel), jmespath==0.9.4(wheel), six==1.12.0(wheel), numpy==1.16.3(wheel), boto==2.49.0(wheel), rsa==3.4.2(wheel), joblib==0.13.2(wheel), docutils==0.14(wheel), idna==2.8(wheel), datadog==0.28.0(wheel)}
2019-05-10 10:21:41 Build missing wheels from sdists (C compiling False): {pyyaml==3.13(sdist)}
2019-05-10 10:21:41 calling pip wheel --no-deps --wheel-dir /var/folders/cs/xfy7j9k12gvc12l0v9tvt0k1l7nvry/T/tmpx8snqxbs /var/folders/cs/xfy7j9k12gvc12l0v9tvt0k1l7nvry/T/tmpx8snqxbs/PyYAML-3.13.tar.gz
...

2019-05-10 10:21:42 Final compatible: {ply==3.11(wheel), html2text==2018.1.9(wheel), requests==2.21.0(wheel), colorama==0.3.9(wheel), psycopg2==2.7.7(wheel), pyasn1==0.4.5(wheel), decorator==4.4.0(wheel), binarizer==0.0.1(wheel), certifi==2019.3.9(wheel), scikit-learn==0.21.0(wheel), scipy==1.2.1(wheel), s3transfer==0.2.0(wheel), python-dateutil==2.8.0(wheel), chardet==3.0.4(wheel), botocore==1.12.145(wheel), scikit-multilearn==0.2.0(wheel), awscli==1.16.155(wheel), boto3==1.9.145(wheel), rbt-utilities==0.0.1(wheel), article-data==0.0.1(wheel), awscli-wrapper==0.0.1(wheel), vectorizer==0.0.1(wheel), classifier==0.0.1(wheel), urllib3==1.24.3(wheel), nltk==3.4.1(wheel), jmespath==0.9.4(wheel), six==1.12.0(wheel), numpy==1.16.3(wheel), boto==2.49.0(wheel), rsa==3.4.2(wheel), joblib==0.13.2(wheel), docutils==0.14(wheel), idna==2.8(wheel), datadog==0.28.0(wheel)}
2019-05-10 10:21:42 Final incompatible: {scikit-learn==0.21.0(wheel), scipy==1.2.1(wheel), pyyaml==3.13(wheel), numpy==1.16.3(wheel), psycopg2==2.7.7(wheel)}
2019-05-10 10:21:42 Final missing wheels: {pyyaml==3.13(sdist)}
2019-05-10 10:21:47 PythonPipBuilder:ResolveDependencies failed
Traceback (most recent call last):
  File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/aws_lambda_builders/workflows/python_pip/actions.py", line 39, in execute
    self.scratch_dir
  File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/aws_lambda_builders/workflows/python_pip/packager.py", line 143, in build_dependencies
    requirements_path, artifacts_dir_path, scratch_dir_path)
  File "/usr/local/Cellar/aws-sam-cli/0.15.0/libexec/lib/python3.7/site-packages/aws_lambda_builders/workflows/python_pip/packager.py", line 212, in build_site_packages
    raise MissingDependencyError(packages_without_wheels)
aws_lambda_builders.workflows.python_pip.packager.MissingDependencyError: {pyyaml==3.13(sdist)}

(note: the other missing ones are local project specific packages each with their own setup.py file in the same repo)

Expected result

I expect the build to succeed

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Mac OS Sierra
  2. sam --version: SAM CLI, version 0.15.0

NealHumphrey avatar May 10 '19 14:05 NealHumphrey

I get a similar issue for sam cli version 0.22.0:

C:\...\devhome\git\proj>virtualenv -p 3 venv
C:\...\devhome\git\proj>pip install pyyaml==5.1.2 awscli aws-sam-cli==0.22.0
C:\...\devhome\git\proj>.\venv\Scripts\activate.bat

(venv) C:\...\devhome\git\proj>sam build
Building resource 'ServerlessFunction'
Running PythonPipBuilder:ResolveDependencies

Build Failed
Error: PythonPipBuilder:ResolveDependencies - {pyyaml==5.1.2(wheel)}

(venv) C:\...\devhome\git\proj>sam --version
SAM CLI, version 0.22.0

It complains whether it's pyyaml 3.13 or 5.1.2.

chtompki avatar Sep 23 '19 14:09 chtompki

Have you tried sam build --use-container

sriram-mv avatar Sep 23 '19 23:09 sriram-mv

I am facing the same issue, also faced this issue with --use-container flag. My requirement file has simplejson package which is casuing the issue. If I remove this package, build is successful. My sam cli version on ubuntu is: SAM CLI, version 0.22.0

Here are the sam build logs:

Using SAM Template at /home/pranav/sam-app2/template.yaml Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics 'build' command is called No Parameters detected in the template 2 resources found in the template Found Serverless function with name='SyncAnswer' and CodeUri='./rtre' Building resource 'SyncAnswer' Loading workflow module 'aws_lambda_builders.workflows' Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip', application_framework=None)' Registering workflow 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)' Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bundler', application_framework=None)' Registering workflow 'GoDepBuilder' with capability 'Capability(language='go', dependency_manager='dep', application_framework=None)' Registering workflow 'GoModulesBuilder' with capability 'Capability(language='go', dependency_manager='modules', application_framework=None)' Registering workflow 'JavaGradleWorkflow' with capability 'Capability(language='java', dependency_manager='gradle', application_framework=None)' Registering workflow 'JavaMavenWorkflow' with capability 'Capability(language='java', dependency_manager='maven', application_framework=None)' Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)' Found workflow 'PythonPipBuilder' to support capabilities 'Capability(language='python', dependency_manager='pip', application_framework=None)' Running workflow 'PythonPipBuilder' Running PythonPipBuilder:ResolveDependencies calling pip download -r /home/pranav/sam-app2/rtre/requirements.txt --dest /tmp/tmphobz26jm Full dependency closure: {simplejson==3.16.0(sdist)} initial compatible: set() initial incompatible: {simplejson==3.16.0(sdist)} Downloading missing wheels: {simplejson==3.16.0(sdist)} calling pip download --only-binary=:all: --no-deps --platform manylinux1_x86_64 --implementation cp --abi cp36m --dest /tmp/tmphobz26jm simplejson==3.16.0 compatible wheels after second download pass: set() Build missing wheels from sdists (C compiling True): {simplejson==3.16.0(sdist)} calling pip wheel --no-deps --wheel-dir /tmp/tmphobz26jm /tmp/tmphobz26jm/simplejson-3.16.0.tar.gz compatible after building wheels (no C compiling): set() Build missing wheels from sdists (C compiling False): {simplejson==3.16.0(sdist)} calling pip wheel --no-deps --wheel-dir /tmp/tmphobz26jm /tmp/tmphobz26jm/simplejson-3.16.0.tar.gz compatible after building wheels (C compiling): set() Final compatible: set() Final incompatible: set() Final missing wheels: {simplejson==3.16.0(sdist)} PythonPipBuilder:ResolveDependencies failed Traceback (most recent call last): File "/home/pranav/.local/lib/python3.6/site-packages/aws_lambda_builders/workflows/python_pip/actions.py", line 39, in execute requirements_path=self.manifest_path File "/home/pranav/.local/lib/python3.6/site-packages/aws_lambda_builders/workflows/python_pip/packager.py", line 143, in build_dependencies requirements_path, artifacts_dir_path, scratch_dir_path) File "/home/pranav/.local/lib/python3.6/site-packages/aws_lambda_builders/workflows/python_pip/packager.py", line 212, in build_site_packages raise MissingDependencyError(packages_without_wheels) aws_lambda_builders.workflows.python_pip.packager.MissingDependencyError: {simplejson==3.16.0(sdist)}

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/pranav/.local/lib/python3.6/site-packages/aws_lambda_builders/workflow.py", line 248, in run action.execute() File "/home/pranav/.local/lib/python3.6/site-packages/aws_lambda_builders/workflows/python_pip/actions.py", line 42, in execute raise ActionFailedError(str(ex)) aws_lambda_builders.actions.ActionFailedError: {simplejson==3.16.0(sdist)}

Build Failed Sending Telemetry: {'metrics': [{'commandRun': {'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'duration': 6133, 'exitReason': 'UserException', 'exitCode': 1, 'requestId': '88c9c2cc-ac6b-47dd-b4a9-89c2bca84d4a', 'installationId': '2c74bd7d-fc80-4819-bb96-14ecab00ed61', 'sessionId': 'd27702d2-7e93-4cbb-a83d-2d575f5c9217', 'executionEnvironment': 'CLI', 'pyversion': '3.6.8', 'samcliVersion': '0.22.0'}}]} HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1) Error: PythonPipBuilder:ResolveDependencies - {simplejson==3.16.0(sdist)}

pranav08 avatar Oct 07 '19 13:10 pranav08

Just saw that there were updates to this thread. We abandoned sam build as a solution and instead now mock the lambda call with a local-only Flask app.

We were not able to use --use-container as a solution, because of a different issue where sam build would not work with local packages, i.e. when we had import paths like this in our Pipfile (to share code across multiple lambdas and a deployed API):

rbt_utilities = {editable = true,path = "./../../lib/rbt_utilities"}

NealHumphrey avatar Oct 07 '19 14:10 NealHumphrey

Thank you so much for the reply. Do you know how to mock lambda call using flask ? Another thing is how do you upload all the dependencies packages as a layer if not using sam build ?

pranav08 avatar Oct 07 '19 15:10 pranav08

Just make a Flask app as a separate file and add an endpoint to it e.g. /test that just executes your_lambda.handler().

We deploy with CloudFormation: https://aws.amazon.com/blogs/infrastructure-and-automation/deploying-aws-lambda-functions-using-aws-cloudformation-the-portable-way/

NealHumphrey avatar Oct 07 '19 15:10 NealHumphrey

Was able to buid pyyaml as well simplejson within a container, so closing this issue.

sriram-mv avatar Feb 08 '20 00:02 sriram-mv