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

时间:2019-02-13 09:12:12

标签: amazon-web-services aws-sam aws-sam-cli

我想开始使用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

3 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

我运行了chmod a+rw requirements.txt,容器可以成功看到该文件。如果您确实对此感到担心,那么您可能只能执行+r

答案 2 :(得分:0)

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

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

在这种情况下:

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