Search code examples
amazon-web-servicesaws-samrequirements.txtaws-sam-cli

AWS SAM Accelerate fails to resolve dependencies when building application


I'm trying to use SAM Accelerate as recommended by AWS. However, the sam sync command is failing

PythonPipBuilder:ResolveDependencies - Could not satisfy the requirement: jsonpickle==2.1.0

The requirement for jsonpickle is included in the requirements.txt file, and it's installed locally.

foo@bar:~/sam-project$ pip freeze | grep jsonpickle
jsonpickle==2.1.0

The exact same error occurs when I use sam build, but I'm able to use the sam build -u to use a container and make the build work. Unfortunately that doesn't seem to be an option for sam sync.

I have found a few occurrences of a similar issue, but none of them address the root cause and this I am unsure of how to fix this.


Full output

foo@bar:~/sam-project$ sam sync --watch

The SAM CLI will use the AWS Lambda, Amazon API Gateway, and AWS StepFunctions APIs to upload your code without 
performing a CloudFormation deployment. This will cause drift in your CloudFormation stack. 
**The sync command should only be used against a development stack**.
Confirm that you are synchronizing a development stack.

Enter Y to proceed with the command, or enter N to cancel:
 [Y/n]: y
Queued infra sync. Wating for in progress code syncs to complete...
Starting infra sync.
Manifest file is changed (new hash: 1719a58de4024a0928ae0e3ddf42ac82) or dependency folder (.aws-sam/deps/ce2e5caa-e309-401a-8ab1-425d3c3e399d) is missing for (CoreLayer), downloading dependencies and copying/building source
Building layer 'CoreLayer'
Running PythonPipBuilder:CleanUp
Clean up action: .aws-sam/deps/ce2e5caa-e309-401a-8ab1-425d3c3e399d does not exist and will be skipped.
Running PythonPipBuilder:ResolveDependencies

Build Failed
Failed to sync infra. Code sync is paused until template/stack is fixed.
Traceback (most recent call last):
  File "aws_lambda_builders/workflows/python_pip/actions.py", line 54, in execute
  File "aws_lambda_builders/workflows/python_pip/packager.py", line 156, in build_dependencies
  File "aws_lambda_builders/workflows/python_pip/packager.py", line 258, in build_site_packages
  File "aws_lambda_builders/workflows/python_pip/packager.py", line 282, in _download_dependencies
  File "aws_lambda_builders/workflows/python_pip/packager.py", line 365, in _download_all_dependencies
  File "aws_lambda_builders/workflows/python_pip/packager.py", line 717, in download_all_dependencies
aws_lambda_builders.workflows.python_pip.packager.NoSuchPackageError: Could not satisfy the requirement: jsonpickle==2.1.0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "aws_lambda_builders/workflow.py", line 301, in run
  File "aws_lambda_builders/workflows/python_pip/actions.py", line 57, in execute
aws_lambda_builders.actions.ActionFailedError: Could not satisfy the requirement: jsonpickle==2.1.0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "samcli/lib/build/app_builder.py", line 760, in _build_function_in_process
  File "aws_lambda_builders/builder.py", line 164, in build
  File "aws_lambda_builders/workflow.py", line 95, in wrapper
  File "aws_lambda_builders/workflow.py", line 308, in run
aws_lambda_builders.exceptions.WorkflowFailedError: PythonPipBuilder:ResolveDependencies - Could not satisfy the requirement: jsonpickle==2.1.0

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "samcli/commands/build/build_context.py", line 248, in run
  File "samcli/lib/build/app_builder.py", line 221, in build
  File "samcli/lib/build/build_strategy.py", line 358, in build
  File "samcli/lib/build/build_strategy.py", line 78, in build
  File "samcli/lib/build/build_strategy.py", line 361, in _build_layers
  File "samcli/lib/build/build_strategy.py", line 380, in _run_builds_async
  File "samcli/lib/utils/async_utils.py", line 131, in run_async
  File "samcli/lib/utils/async_utils.py", line 90, in run_given_tasks_async
  File "asyncio/base_events.py", line 587, in run_until_complete
  File "samcli/lib/utils/async_utils.py", line 58, in _run_given_tasks_async
  File "concurrent/futures/thread.py", line 57, in run
  File "samcli/lib/build/build_strategy.py", line 388, in build_single_layer_definition
  File "samcli/lib/build/build_strategy.py", line 546, in build_single_layer_definition
  File "samcli/lib/build/build_strategy.py", line 430, in build_single_layer_definition
  File "samcli/lib/build/build_strategy.py", line 218, in build_single_layer_definition
  File "samcli/lib/build/app_builder.py", line 552, in _build_layer
  File "samcli/lib/build/app_builder.py", line 763, in _build_function_in_process
samcli.lib.build.exceptions.BuildError: PythonPipBuilder:ResolveDependencies - Could not satisfy the requirement: jsonpickle==2.1.0

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "samcli/lib/sync/watch_manager.py", line 190, in _execute_infra_sync
  File "samcli/lib/sync/watch_manager.py", line 142, in _execute_infra_context
  File "samcli/commands/build/build_context.py", line 308, in run
samcli.commands.exceptions.UserException: PythonPipBuilder:ResolveDependencies - Could not satisfy the requirement: jsonpickle==2.1.0
samcli.commands.exceptions.UserException: PythonPipBuilder:ResolveDependencies - Could not satisfy the requirement: jsonpickle==2.1.0

Solution

  • Unfortunately no one was able to assist here, so I opened an issue on GitHub.

    Eventually the issue became clear and it's not actually an issue with SAM. The problem is that I use an AWS BuildArtifact feed, so any sam build or sam sync action will try and pull packages from that feed. However, the token for that feed expires after 12 hours.

    The issue remains open and the SAM team are investigating the error that is displayed, and hopefully they will implement a solution that will surface the underlying error message, which would have made diagnosing this issue a whole lot easier.