简体   繁体   English

使用 AWS SAM 创建 Hello World 应用程序:运行“sam build”时出现问题

[英]Creating a Hello World application using AWS SAM : issue when running "sam build"

I am just getting started with AWS SAM.我刚刚开始使用 AWS SAM。 I tried following Amazon's tutorial : https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-getting-started-hello-world.html .我尝试遵循亚马逊的教程: https : //docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-getting-started-hello-world.html But I am stuck at Step #2 : When I run "sam build" in the directory of the application, i get this error :但我被困在第 2 步:当我在应用程序目录中运行“sam build”时,出现此错误:

C:\Users\emman\HelloWorldAPI>sam build
Building resource 'HelloWorldFunction'
Running PythonPipBuilder:ResolveDependencies

Build Failed
Error: PythonPipBuilder:ResolveDependencies - Could not satisfy the requirement: requests

I am using Python 3.7.7 on anaconda.我在 anaconda 上使用 Python 3.7.7。 How can I fix this dependency problem ?我该如何解决这个依赖问题?

Here is the full debug :这是完整的调试:

sam build --debug
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='HelloWorldFunction' and CodeUri='hello_world/'
Building resource 'HelloWorldFunction'
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 C:\Users\emman\HelloWorldAPI\hello_world\requirements.txt --dest C:\Users\emman\AppData\Local\Temp\tmpdzzen475
PythonPipBuilder:ResolveDependencies failed
Traceback (most recent call last):
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\aws_lambda_builders\workflows\python_pip\actions.py", line 42, in execute
    requirements_path=self.manifest_path,
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\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 "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\aws_lambda_builders\workflows\python_pip\packager.py", line 198, in build_site_packages
    wheels, packages_without_wheels = self._download_dependencies(scratch_directory, requirements_filepath)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\aws_lambda_builders\workflows\python_pip\packager.py", line 222, in _download_dependencies
    deps = self._download_all_dependencies(requirements_filename, directory)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\aws_lambda_builders\workflows\python_pip\packager.py", line 305, in _download_all_dependencies
    self._pip.download_all_dependencies(requirements_filename, directory)
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\aws_lambda_builders\workflows\python_pip\packager.py", line 594, in download_all_dependencies
    raise NoSuchPackageError(str(package_name))
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 "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\aws_lambda_builders\workflow.py", line 269, in run
    action.execute()
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\aws_lambda_builders\workflows\python_pip\actions.py", line 45, in execute
    raise ActionFailedError(str(ex))
aws_lambda_builders.actions.ActionFailedError: Could not satisfy the requirement: requests

Build Failed
Sending Telemetry: {'metrics': [{'commandRun': {'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'duration': 12362, 'exitReason': 'BuildError', 'exitCode': 1, 'requestId': '3281a750-00b0-409a-9248-d50da2c6873a', 'installationId': 'cd8fef36-a3f5-4145-9f80-47b50c4113c7', 'sessionId': '224c2d07-0766-4233-96a1-4433dc488353', 'executionEnvironment': 'CLI', 'pyversion': '3.7.6', 'samcliVersion': '0.47.0'}}]}
HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Error: PythonPipBuilder:ResolveDependencies - Could not satisfy the requirement: requests

I tried looking at the requirements.txt file.我尝试查看 requirements.txt 文件。 The only line was "requests".唯一的一行是“请求”。 I tried deleting it, and running "sam build" again.我尝试删除它,然后再次运行“sam build”。 The build succeeded, but I am not quite sure it is that easy... Here is what the "sam build" returns :构建成功,但我不太确定它是否那么容易......这是“sam build”返回的内容:


Built Artifacts  : .aws-sam\build
Built Template   : .aws-sam\build\template.yaml

Commands you can use next
=========================
[*] Invoke Function: sam local invoke
[*] Deploy: sam deploy --guided

I found another post saying I should run :我发现另一篇文章说我应该运行:

pip install wheel```

I did that in the anaconda prompt, but the module is already installed. 
I wonder if there is a conflict between two different pip applications...

Anaconda runs python 3.7.7 and the telemetry of "sam build --debug" returns :
```'pyversion': '3.7.6'```

I solved my issue by uninstalling anaconda, and by downloading the stock version of Python instead.我通过卸载 anaconda 并下载 Python 的股票版本来解决我的问题。

I'm still curious to know if Anaconda could work however.我仍然很想知道 Anaconda 是否可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM