部署 SAM 教程应用时找不到要求文件



我想开始使用 aws-sam 在本地测试我的 lambdas。我尝试从 https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-quick-start.html 学习教程

我使用sam init --runtime python3.6创建了示例应用程序然后当我这样做时 sam build --use-container 我得到这个奇怪的异常,它无法获得要求.txt。我该怎么办?我使用 pyhon 3.7.2

2019-02-13 10:06:42 Using SAM Template at C:UsersXXXXDocumentssam-apptemplate.yaml
2019-02-13 10:06:42 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-p
2019-02-13 10:06:42 Changing event name from before-call.apigateway to before-call.api-gateway
2019-02-13 10:06:42 Changing event name from request-created.machinelearning.Predict to request-created.machine
.Predict
2019-02-13 10:06:42 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to be
meter-build.auto-scaling.CreateLaunchConfiguration
2019-02-13 10:06:42 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-02-13 10:06:42 Changing event name from request-created.cloudsearchdomain.Search to request-created.clouds
ain.Search
2019-02-13 10:06:42 Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to d
o-scaling.CreateLaunchConfiguration.complete-section
2019-02-13 10:06:42 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-b
dwatch-logs.CreateExportTask
2019-02-13 10:06:42 Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch
ateExportTask.complete-section
2019-02-13 10:06:42 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-paramete
loudsearch-domain.Search
2019-02-13 10:06:42 Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudse
in.Search.complete-section
2019-02-13 10:06:42 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-p
2019-02-13 10:06:42 Changing event name from before-call.apigateway to before-call.api-gateway
2019-02-13 10:06:42 Changing event name from request-created.machinelearning.Predict to request-created.machine
.Predict
2019-02-13 10:06:42 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to be
meter-build.auto-scaling.CreateLaunchConfiguration
2019-02-13 10:06:42 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-02-13 10:06:42 Changing event name from request-created.cloudsearchdomain.Search to request-created.clouds
ain.Search
2019-02-13 10:06:42 Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to d
o-scaling.CreateLaunchConfiguration.complete-section
2019-02-13 10:06:42 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-b
dwatch-logs.CreateExportTask
2019-02-13 10:06:42 Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch
ateExportTask.complete-section
2019-02-13 10:06:42 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-paramete
loudsearch-domain.Search
2019-02-13 10:06:42 Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudse
in.Search.complete-section
2019-02-13 10:06:42 'build' command is called
2019-02-13 10:06:42 Starting Build inside a container
2019-02-13 10:06:42 Looking for credentials via: env
2019-02-13 10:06:42 Looking for credentials via: assume-role
2019-02-13 10:06:42 Looking for credentials via: shared-credentials-file
2019-02-13 10:06:42 Found credentials in shared credentials file: ~/.aws/credentials
2019-02-13 10:06:42 Loading JSON file: C:Program FilesAmazonAWSSAMCLIruntimelibsite-packagesbotocoredat
ts.json
2019-02-13 10:06:42 Event choose-service-name: calling handler <function handle_service_name_alias at 0x0000023
>
2019-02-13 10:06:42 Loading JSON file: C:Program FilesAmazonAWSSAMCLIruntimelibsite-packagesbotocoredat
essrepo2017-09-08service-2.json
2019-02-13 10:06:42 Event creating-client-class.serverlessapplicationrepository: calling handler <function add_
presigned_url at 0x00000237DD8E8EA0>
2019-02-13 10:06:42 The s3 config key is not a dictionary type, ignoring its value of: None
2019-02-13 10:06:42 Setting serverlessrepo timeout as (60, 60)
2019-02-13 10:06:42 Loading JSON file: C:Program FilesAmazonAWSSAMCLIruntimelibsite-packagesbotocoredat
json
2019-02-13 10:06:42 Registering retry handlers for service: serverlessrepo
2019-02-13 10:06:42 No Parameters detected in the template
2019-02-13 10:06:42 2 resources found in the template
2019-02-13 10:06:42 Found Serverless function with name='HelloWorldFunction' and CodeUri='hello_world/'
2019-02-13 10:06:42 Trying paths: ['C:\Users\XXXX\.docker\config.json', 'C:\Users\XXXX\.dockercf
2019-02-13 10:06:42 Found file at path: C:UsersXXXX.dockerconfig.json
2019-02-13 10:06:42 Found 'credsStore' section
2019-02-13 10:06:42 Building resource 'HelloWorldFunction'
2019-02-13 10:06:43 Trying paths: ['C:\Users\XXXX\.docker\config.json', 'C:\Users\XXXX\.dockercf
2019-02-13 10:06:43 Found file at path: C:UsersXXXX.dockerconfig.json
2019-02-13 10:06:43 Found 'credsStore' section
2019-02-13 10:06:43 http://localhost:None "GET /v1.35/images/lambci/lambda:build-python3.6/json HTTP/1.1" 200 N
2019-02-13 10:06:43 Looking for auth config
2019-02-13 10:06:43 Using credentials store "wincred"
2019-02-13 10:06:43 Looking for auth entry for 'https://index.docker.io/v1/'
2019-02-13 10:06:43 No entry found
2019-02-13 10:06:43 No entry in credstore - fetching from auth dict
2019-02-13 10:06:43 Looking for auth entry for 'docker.io'
2019-02-13 10:06:43 No entry found
2019-02-13 10:06:43 No auth config found
2019-02-13 10:06:45 http://localhost:None "POST /v1.35/images/create?tag=build-python3.6&fromImage=lambci%2Flam
1.1" 200 None
Fetching lambci/lambda:build-python3.6 Docker container image......
2019-02-13 10:06:45 Mounting C:UsersXXXXDocumentssam-apphello_world as /tmp/samcli/source:ro inside ru
tainer
2019-02-13 10:06:45 http://localhost:None "POST /v1.35/containers/create HTTP/1.1" 201 90
2019-02-13 10:06:45 http://localhost:None "GET /v1.35/containers/daa68e5aa3872c114bf1ed108626f6e526829570d9affa
523a55d8c/json HTTP/1.1" 200 None
2019-02-13 10:06:45 http://localhost:None "GET /v1.35/containers/daa68e5aa3872c114bf1ed108626f6e526829570d9affa
523a55d8c/json HTTP/1.1" 200 None
2019-02-13 10:06:47 http://localhost:None "POST /v1.35/containers/daa68e5aa3872c114bf1ed108626f6e526829570d9aff
9523a55d8c/start HTTP/1.1" 204 0
2019-02-13 10:06:47 http://localhost:None "GET /v1.35/containers/daa68e5aa3872c114bf1ed108626f6e526829570d9affa
523a55d8c/json HTTP/1.1" 200 None
2019-02-13 10:06:47 http://localhost:None "POST /containers/daa68e5aa3872c114bf1ed108626f6e526829570d9affa75e3b
5d8c/attach?stdout=1&stderr=1&logs=1&stream=1&stdin=0 HTTP/1.1" 101 0
Using the request object from command line argument
Loading workflow module 'aws_lambda_builders.workflows'
Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip'
tion_framework=None)'
Registering workflow 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm'
tion_framework=None)'
Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bund
lication_framework=None)'
Found workflow 'PythonPipBuilder' to support capabilities 'Capability(language='python', dependency_manager='pi
cation_framework=None)'
Running workflow 'PythonPipBuilder'
Running PythonPipBuilder:ResolveDependencies
PythonPipBuilder:ResolveDependencies failed
Traceback (most recent call last):
  File "/var/lang/lib/python3.6/site-packages/aws_lambda_builders/workflows/python_pip/actions.py", line 27, in
    self.scratch_dir
  File "/var/lang/lib/python3.6/site-packages/aws_lambda_builders/workflows/python_pip/packager.py", line 140,
dependencies
    raise RequirementsFileNotFoundError(requirements_path)
aws_lambda_builders.workflows.python_pip.packager.RequirementsFileNotFoundError: Requirements file not found: /
i/source/requirements.txt
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/var/lang/lib/python3.6/site-packages/aws_lambda_builders/workflow.py", line 164, in run
    action.execute()
  File "/var/lang/lib/python3.6/site-packages/aws_lambda_builders/workflows/python_pip/actions.py", line 30, in
    raise ActionFailedError(str(ex))
aws_lambda_builders.actions.ActionFailedError: Requirements file not found: /tmp/samcli/source/requirements.txt
Builder workflow failed
Traceback (most recent call last):
  File "/var/lang/lib/python3.6/site-packages/aws_lambda_builders/workflows/python_pip/actions.py", line 27, in
    self.scratch_dir
  File "/var/lang/lib/python3.6/site-packages/aws_lambda_builders/workflows/python_pip/packager.py", line 140,
dependencies
    raise RequirementsFileNotFoundError(requirements_path)
aws_lambda_builders.workflows.python_pip.packager.RequirementsFileNotFoundError: Requirements file not found: /
i/source/requirements.txt
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/var/lang/lib/python3.6/site-packages/aws_lambda_builders/workflow.py", line 164, in run
    action.execute()
  File "/var/lang/lib/python3.6/site-packages/aws_lambda_builders/workflows/python_pip/actions.py", line 30, in
    raise ActionFailedError(str(ex))
aws_lambda_builders.actions.ActionFailedError: Requirements file not found: /tmp/samcli/source/requirements.txt
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/var/lang/lib/python3.6/site-packages/aws_lambda_builders/__main__.py", line 98, in main
    options=params["options"])
  File "/var/lang/lib/python3.6/site-packages/aws_lambda_builders/builder.py", line 108, in build
    return workflow.run()
  File "/var/lang/lib/python3.6/site-packages/aws_lambda_builders/workflow.py", line 173, in run
    reason=str(ex))
aws_lambda_builders.exceptions.WorkflowFailedError: PythonPipBuilder:ResolveDependencies - Requirements file no
/tmp/samcli/source/requirements.txt
2019-02-13 10:06:47 Build inside container returned response {"jsonrpc": "2.0", "id": 1, "error": {"code": 400,
": "PythonPipBuilder:ResolveDependencies - Requirements file not found: /tmp/samcli/source/requirements.txt"}}
2019-02-13 10:06:48 http://localhost:None "GET /v1.35/containers/daa68e5aa3872c114bf1ed108626f6e526829570d9affa
523a55d8c/json HTTP/1.1" 200 None
2019-02-13 10:06:48 http://localhost:None "DELETE /v1.35/containers/daa68e5aa3872c114bf1ed108626f6e526829570d9a
049523a55d8c?v=False&link=False&force=True HTTP/1.1" 204 0
Build Failed
Error: PythonPipBuilder:ResolveDependencies - Requirements file not found: /tmp/samcli/source/requirements.txt

如果您使用的是 docker,请将需求.txt复制到项目的根目录。这应该可以解决它。

对我来说,问题是文件的权限requirements.txt

我运行了chmod a+rw requirements.txt,容器可以成功看到该文件。如果你真的关心这一点,你可能只能做+r

以下错误可能是由于 CLI 无法连接到本地 docker 中运行的容器导致的。

Requirements file not found: /tmp/samcli/source/requirements.txt

如果是这种情况:

  • 验证 Docker 是否正在运行。
  • 验证 Docker 是否正在共享本地驱动器。
  • 如果 Docker 正在运行,请确保防火墙未阻止 docker。要对此进行测试,请尝试共享共享本地驱动器(如果已共享,请取消共享,然后再次共享(。如果被阻止,将自动出现一个对话框。

最新更新