aws / aws/aws-sam-cli

SAM Accelerate fails to resolve dependencies during build

Open
#4,054 7 comments 0 reactions 0 assignees View on GitHub
blocked/more-info-needed maintainer/need-followup
Dominant language
Python
Stars
6.7k
Forks
1.2k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

### Description:

I cannot get the sample `hello-world` SAM application to work with SAM Accelerate to work. No matter what I do, I see an error.

```shell
samcli.commands.exceptions.UserException: PythonPipBuilder:ResolveDependencies - Could not satisfy the requirement: requests
```

Note that `requests` is installed and available to my chosen runtime, `python3.8`.

```
foo@bar:~/sam-tutorial$ python3.8 -m pip freeze | grep requests
requests==2.28.1
```

Also note that I am experiencing this issue with an actual application. I have created a [StackOverflow question](https://stackoverflow.com/questions/72912747/aws-sam-accelerate-fails-to-resolve-dependencies-when-building-application), but as yet no one has responded. I'm hoping someone here will be able to help.

### Steps to reproduce:

I followed the steps as described in [Getting started with AWS SAM Accelerate](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/accelerate-getting-started.html).

The only difference is that I used runtime `python3.8`, as that is my chosen runtime.

### Observed result:

am init --app-template hello-world --name sam-tutorial --package-type Zip --runtime python3.8 --debug

```shell
2022-07-13 11:12:56,158 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2022-07-13 11:12:56,158 | Using config file: samconfig.toml, config environment: default
2022-07-13 11:12:56,158 | Expand command line arguments to:
2022-07-13 11:12:56,158 | --app_template=hello-world --name=sam-tutorial --package_type=Zip --runtime=python3.8 --output_dir=.
2022-07-13 11:12:56,529 | Template runtime graalvm.java11 (provided.al2) does not match filter value python3.8
2022-07-13 11:12:56,529 | Template runtime graalvm.java17 (provided.al2) does not match filter value python3.8
2022-07-13 11:12:56,529 | Template runtime dotnetcore3.1 does not match filter value python3.8
2022-07-13 11:12:56,529 | Template runtime dotnet6 does not match filter value python3.8
2022-07-13 11:12:56,529 | Template runtime go1.x does not match filter value python3.8
2022-07-13 11:12:56,530 | Template runtime java8 does not match filter value python3.8
2022-07-13 11:12:56,530 | Template runtime java8.al2 does not match filter value python3.8
2022-07-13 11:12:56,530 | Template runtime java11 does not match filter value python3.8
2022-07-13 11:12:56,530 | Template runtime nodejs16.x does not match filter value python3.8
2022-07-13 11:12:56,530 | Template runtime amazon/nodejs16.x-base does not match filter value python3.8
2022-07-13 11:12:56,530 | Template runtime nodejs14.x does not match filter value python3.8
2022-07-13 11:12:56,530 | Template runtime nodejs12.x does not match filter value python3.8
2022-07-13 11:12:56,530 | Template runtime python3.6 does not match filter value python3.8
2022-07-13 11:12:56,530 | Template runtime python3.7 does not match filter value python3.8
2022-07-13 11:12:56,530 | Template runtime python3.9 does not match filter value python3.8
2022-07-13 11:12:56,530 | Template runtime ruby2.7 does not match filter value python3.8
2022-07-13 11:12:56,531 | Template runtime rust (provided.al2) does not match filter value python3.8
2022-07-13 11:12:56,531 | Template runtime amazon/nodejs14.x-base does not match filter value python3.8
2022-07-13 11:12:56,531 | Template runtime amazon/nodejs12.x-base does not match filter value python3.8
2022-07-13 11:12:56,531 | Template runtime amazon/python3.8-base does not match filter value python3.8
2022-07-13 11:12:56,531 | Template runtime amazon/python3.9-base does not match filter value python3.8
2022-07-13 11:12:56,531 | Template runtime amazon/ruby2.7-base does not match filter value python3.8
2022-07-13 11:12:56,531 | Template runtime amazon/go1.x-base does not match filter value python3.8
2022-07-13 11:12:56,531 | Template runtime amazon/java11-base does not match filter value python3.8
2022-07-13 11:12:56,531 | Template runtime amazon/dotnet6-base does not match filter value python3.8
2022-07-13 11:12:56,531 | Template runtime amazon/dotnet5.0-base does not match filter value python3.8
2022-07-13 11:12:56,531 | Template runtime amazon/dotnetcore3.1-base does not match filter value python3.8
2022-07-13 11:12:56,531 | Template runtime amazon/python3.7-base does not match filter value python3.8
2022-07-13 11:12:56,531 | Template runtime amazon/python3.6-base does not match filter value python3.8
2022-07-13 11:12:56,531 | Template runtime amazon/java8-base does not match filter value python3.8
2022-07-13 11:12:56,531 | Template runtime amazon/java8.al2-base does not match filter value python3.8

Based on your selections, the only Template available is Hello World Example.
We will proceed to selecting the Template as Hello World Example.

Based on your selections, the only dependency manager available is pip.
We will proceed copying the template using pip.

Would you like to enable X-Ray tracing on the function(s) in your application? [y/N]: X-Ray will incur an additional cost. View https://aws.amazon.com/xray/pricing/ for more details
2022-07-13 11:18:26,388 |
Cloning from https://github.com/aws/aws-sam-cli-app-templates (process may take a moment)
2022-07-13 11:18:47,685 | Removing old repo at /home/dgard/.aws-sam/aws-sam-cli-app-templates
2022-07-13 11:18:47,755 | Copying from /tmp/tmpekpdbxi9/aws-sam-cli-app-templates to /home/dgard/.aws-sam/aws-sam-cli-app-templates

-----------------------
Generating application:
-----------------------
Name: sam-tutorial
Runtime: python3.8
Architectures: x86_64
Dependency Manager: pip
Application Template: hello-world
Output Directory: .

Next steps can be found in the README file at ./sam-tutorial/README.md

Commands you can use next
=========================
[*] Create pipeline: cd sam-tutorial && sam pipeline init --bootstrap
[*] Validate SAM template: sam validate
[*] Test Function in the Cloud: sam sync --stack-name {stack-name} --watch

2022-07-13 11:18:48,074 | Parameters dict created with input given
2022-07-13 11:18:48,074 | {'template': '/home/dgard/.aws-sam/aws-sam-cli-app-templates/python3.8/cookiecutter-aws-sam-hello-python', 'output_dir': '.', 'no_input': True, 'extra_context': {'project_name': 'sam-tutorial', 'runtime': 'python3.8', 'architectures': {'value': ['x86_64']}}}
2022-07-13 11:18:48,074 | Baking a new template with cookiecutter with all parameters
2022-07-13 11:18:48,121 | Template is not provided in context, skip adding project type metric
2022-07-13 11:18:48,122 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '1e45a37f-6666-4c20-92ca-62676513ea66', 'installationId': '74a8e876-2017-4104-be01-699f1ead265d', 'sessionId': '5c1448ea-c3fb-4495-84fc-15f771568140', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.7.10', 'samcliVersion': '1.53.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam init', 'duration': 351964, 'exitReason': 'success', 'exitCode': 0}}]}
2022-07-13 11:18:48,835 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
```

sam sync --watch --stack-name sam-app

```shell
2022-07-13 11:20:51,931 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2022-07-13 11:20:51,935 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2022-07-13 11:20:51,936 | Sending Telemetry: {'metrics': [{'templateWarning': {'requestId': '00725dd7-4d7c-40c6-8886-e1e651c3ab46', 'installationId': '74a8e876-2017-4104-be01-699f1ead265d', 'sessionId': '8ac9906e-406b-4529-bb60-b621f9f688ae', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.7.10', 'samcliVersion': '1.53.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'warningName': 'CodeDeployWarning', 'warningCount': 0}}]}
2022-07-13 11:20:52,661 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
2022-07-13 11:20:52,662 | Sending Telemetry: {'metrics': [{'templateWarning': {'requestId': '22220a5b-939a-4b3c-a442-71f123234dba', 'installationId': '74a8e876-2017-4104-be01-699f1ead265d', 'sessionId': '8ac9906e-406b-4529-bb60-b621f9f688ae', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.7.10', 'samcliVersion': '1.53.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'warningName': 'CodeDeployConditionWarning', 'warningCount': 0}}]}
2022-07-13 11:20:53,408 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
2022-07-13 11:20:53,409 | Using config file: samconfig.toml, config environment: default
2022-07-13 11:20:53,409 | Expand command line arguments to:
2022-07-13 11:20:53,409 | --template_file=/home/dgard/sam-tutorial/template.yaml --watch --stack_name=sam-app --dependency_layer --capabilities=('CAPABILITY_NAMED_IAM', 'CAPABILITY_AUTO_EXPAND')

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]: 2022-07-13 11:20:59,321 | Using build directory as .aws-sam/auto-dependency-layer
2022-07-13 11:20:59,326 | No Parameters detected in the template
2022-07-13 11:20:59,339 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource logical id as the resource id
2022-07-13 11:20:59,339 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id
2022-07-13 11:20:59,340 | 0 stacks found in the template
2022-07-13 11:20:59,340 | No Parameters detected in the template
2022-07-13 11:20:59,350 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource logical id as the resource id
2022-07-13 11:20:59,350 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id
2022-07-13 11:20:59,351 | 2 resources found in the stack
2022-07-13 11:20:59,351 | Found Serverless function with name='HelloWorldFunction' and CodeUri='hello_world/'
2022-07-13 11:20:59,351 | --base-dir is not presented, adjusting uri hello_world/ relative to /home/dgard/sam-tutorial/template.yaml
2022-07-13 11:20:59,352 | Entering sync context, previous state: SyncState(dependency_layer=True), current state: SyncState(dependency_layer=True)
2022-07-13 11:20:59,352 | Queued infra sync. Wating for in progress code syncs to complete...
2022-07-13 11:20:59,352 | Starting infra sync.
2022-07-13 11:20:59,357 | No Parameters detected in the template
2022-07-13 11:20:59,367 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource logical id as the resource id
2022-07-13 11:20:59,367 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id
2022-07-13 11:20:59,367 | 0 stacks found in the template
2022-07-13 11:20:59,367 | No Parameters detected in the template
2022-07-13 11:20:59,377 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource logical id as the resource id
2022-07-13 11:20:59,377 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id
2022-07-13 11:20:59,378 | 2 resources found in the stack
2022-07-13 11:20:59,378 | Found Serverless function with name='HelloWorldFunction' and CodeUri='hello_world/'
2022-07-13 11:20:59,378 | --base-dir is not presented, adjusting uri hello_world/ relative to /home/dgard/sam-tutorial/template.yaml
2022-07-13 11:20:59,383 | Your template contains a resource with logical ID "ServerlessRestApi", which is a reserved logical ID in AWS SAM. It could result in unexpected behaviors and is not recommended.
2022-07-13 11:20:59,383 | Instantiating build definitions
2022-07-13 11:20:59,385 | Same function build definition found, adding function (Previous: BuildDefinition(python3.8, /home/dgard/sam-tutorial/hello_world, Zip, , 1cf4852e-50c5-4085-91a6-4245ec92629b, {}, {}, x86_64, []), Current: BuildDefinition(python3.8, /home/dgard/sam-tutorial/hello_world, Zip, , fd6e32fd-efdb-4abc-b71f-20a46420f4a4, {}, {}, x86_64, []), Function: Function(function_id='HelloWorldFunction', name='HelloWorldFunction', functionname='HelloWorldFunction', runtime='python3.8', memory=None, timeout=3, handler='app.lambda_handler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='/home/dgard/sam-tutorial/hello_world', environment=None, rolearn=None, layers=[], events={'HelloWorld': {'Type': 'Api', 'Properties': {'Path': '/hello', 'Method': 'get', 'RestApiId': 'ServerlessRestApi'}}}, metadata={'SamResourceId': 'HelloWorldFunction'}, inlinecode=None, codesign_config_arn=None, architectures=['x86_64'], function_url_config=None, stack_path=''))
2022-07-13 11:20:59,386 | Async execution started
2022-07-13 11:20:59,386 | Invoking function functools.partial(>, )
2022-07-13 11:20:59,387 | Running incremental build for runtime python3.8 for following resources (HelloWorldFunction)
2022-07-13 11:20:59,387 | Manifest file is changed (new hash: 3298f13049d19cffaa37ca931dd4d421) or dependency folder (.aws-sam/deps/1cf4852e-50c5-4085-91a6-4245ec92629b) is missing for (HelloWorldFunction), downloading dependencies and copying/building source
2022-07-13 11:20:59,387 | Building codeuri: /home/dgard/sam-tutorial/hello_world runtime: python3.8 metadata: {} architecture: x86_64 functions: HelloWorldFunction
2022-07-13 11:20:59,387 | Building to following folder /home/dgard/sam-tutorial/.aws-sam/auto-dependency-layer/HelloWorldFunction
2022-07-13 11:20:59,387 | Waiting for async results
2022-07-13 11:20:59,388 | Loading workflow module 'aws_lambda_builders.workflows'
2022-07-13 11:20:59,390 | Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip', application_framework=None)'
2022-07-13 11:20:59,390 | Registering workflow 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)'
2022-07-13 11:20:59,391 | Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bundler', application_framework=None)'
2022-07-13 11:20:59,392 | Registering workflow 'GoModulesBuilder' with capability 'Capability(language='go', dependency_manager='modules', application_framework=None)'
2022-07-13 11:20:59,393 | Registering workflow 'JavaGradleWorkflow' with capability 'Capability(language='java', dependency_manager='gradle', application_framework=None)'
2022-07-13 11:20:59,394 | Registering workflow 'JavaMavenWorkflow' with capability 'Capability(language='java', dependency_manager='maven', application_framework=None)'
2022-07-13 11:20:59,395 | Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)'
2022-07-13 11:20:59,396 | Registering workflow 'CustomMakeBuilder' with capability 'Capability(language='provided', dependency_manager=None, application_framework=None)'
2022-07-13 11:20:59,397 | Registering workflow 'NodejsNpmEsbuildBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm-esbuild', application_framework=None)'
2022-07-13 11:20:59,397 | Found workflow 'PythonPipBuilder' to support capabilities 'Capability(language='python', dependency_manager='pip', application_framework=None)'
2022-07-13 11:20:59,446 | Running workflow 'PythonPipBuilder'
2022-07-13 11:20:59,446 | Running PythonPipBuilder:CleanUp
2022-07-13 11:20:59,446 | Clean up action: .aws-sam/deps/1cf4852e-50c5-4085-91a6-4245ec92629b does not exist and will be skipped.
2022-07-13 11:20:59,446 | PythonPipBuilder:CleanUp succeeded
2022-07-13 11:20:59,446 | Running PythonPipBuilder:ResolveDependencies
2022-07-13 11:20:59,464 | calling pip download -r /home/dgard/sam-tutorial/hello_world/requirements.txt --dest /tmp/tmpba33lles --exists-action i
2022-07-13 11:21:01,120 | PythonPipBuilder:ResolveDependencies failed
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: requests

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: requests
2022-07-13 11:21:01,121 | Exception raised during the execution

Build Failed
2022-07-13 11:21:01,122 | 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: requests

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: requests

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: requests

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 79, in build
File "samcli/lib/build/build_strategy.py", line 365, in _build_functions
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 391, in build_single_function_definition
File "samcli/lib/build/build_strategy.py", line 530, in build_single_function_definition
File "samcli/lib/build/build_strategy.py", line 424, in build_single_function_definition
File "samcli/lib/build/build_strategy.py", line 171, in build_single_function_definition
File "samcli/lib/build/app_builder.py", line 668, in _build_function
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: requests

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: requests
2022-07-13 11:21:01,127 | No Parameters detected in the template
2022-07-13 11:21:01,138 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource logical id as the resource id
2022-07-13 11:21:01,138 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id
2022-07-13 11:21:01,138 | 0 stacks found in the template
```

### Expected result:

I expected the SAM application to sync, as described in [Getting started with AWS SAM Accelerate](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/accelerate-getting-started.html).

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

1. OS: Ubuntu `20.04`
2. SAM CLI version: `1.53.0`
3. AWS region: `us-east-1`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.