3

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

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

2019-02-13 10:06:42 Using SAM Template at C:\Users\XXXX\Documents\sam-app\template.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 Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\botocore\dat
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 Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\botocore\dat
essrepo\2017-09-08\service-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 Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\botocore\dat
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:\Users\XXXX\.docker\config.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:\Users\XXXX\.docker\config.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:\Users\XXXX\Documents\sam-app\hello_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
4

3 回答 3

3

如果您使用的是 docker,请将 requirements.txt 复制到项目的根目录。那应该解决它。

于 2019-04-12T09:42:49.627 回答
3

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

我跑chmod a+rw requirements.txt了,容器可以成功看到文件。+r只有当你真的担心这一点时,你才能做到这一点。

于 2019-12-06T18:35:08.190 回答
0

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

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

如果是这种情况:

  • 验证 Docker 是否正在运行。
  • 验证 Docker 是否共享本地驱动器。
  • 如果 Docker 正在运行,请确保防火墙没有阻止 docker。要对此进行测试,请尝试共享本地驱动器(如果已共享,请取消共享,然后再次共享)。如果被阻止,将自动出现一个对话框。
于 2020-02-05T13:30:17.990 回答