5

我有一个与 AWS 一起使用的 python 无服务器项目。但是每当我运行 sls deploy 时,我都会收到此错误,并且我在 .serverless 中注意到它实际上并没有压缩文件,只生成 .json 文件。

发生错误:ParserLambdaFunction - 上传的文件必须是非空 zip。

我的 yml 看起来像这样:

service: my-service

provider:
  name: aws
  runtime: python3.6

package:
  individually: True

plugins:
  - serverless-package-python-functions
  - serverless-python-requirements

custom:
  pkgPyFuncs: # plugin configuration
    buildDir: _build

functions:
  parser:
    handler: handler.parser
    package:
      include:
      artifact: ${self:custom.pkgPyFuncs.buildDir}/my-service-dev-parser.zip
    events:
      - http:
          cors: true
          integration: LAMBDA
          passThrough: WHEN_NO_MATCH
          path: /
          method: post
          request: 
            parameters:
              querystring:
                application/json: "$input.path('$.body')"
                url: true
      - cloudwatchLog: '/aws/lambda/pythonParser'

我的 package.json 看起来像这样:

{
  "name": "my-service",
  "description": "",
  "version": "0.1.0",
  "dependencies": {
    "serverless-package-python-functions": "^0.2.3"
  },
  "devDependencies": {
    "serverless-python-requirements": "^3.0.5"
  }
}

我的文件夹结构如下所示:

-my-service
--.serverless
--_pycache_
--_build
--node_modules
--standford-new-2017-06-09
--.gitignore
--handler.py
--package.json
--serverless.yml
--tsconfig.json
--typings.json
4

1 回答 1

1

一方面,您可以简单地删除include或使用

include:
   - ./[put_your_function_code_in_a_folder]
artifact: ....

正如它所说 - 将您的代码放在您的目录的子文件夹中。

于 2017-12-22T09:33:04.873 回答