AWS Lambda错误:无法解压缩上传的文件

时间:2018-06-18 15:33:34

标签: node.js amazon-web-services aws-lambda aws-sdk

我正在尝试使用node.js的aws-sdk包更新lambda函数中的代码。所以我编写了以下脚本来运行部署代码

var AWS = require('aws-sdk');
AWS.config.loadFromPath('./config.json');
var lambda = new AWS.Lambda();

var params = {
    FunctionName: 'FunctionName',
    ZipFile: 'fileb://deploy_package.zip'
}

lambda.updateFunctionCode(params, function(err, data) {
    if (err) console.log(err, err.stack);
    else console.log(data);
});

问题是当我运行脚本时出现以下错误:

{ InvalidParameterValueException: Could not unzip uploaded file. Please check your file, then try to upload again.
    at Object.extractError (C:\Users\jaarnold\Desktop\AlexaSkills\circleCI\node_modules\aws-sdk\lib\protocol\json.js:48:27)
    at Request.extractError (C:\Users\jaarnold\Desktop\AlexaSkills\circleCI\node_modules\aws-sdk\lib\protocol\rest_json.js:52:8)
    at Request.callListeners (C:\Users\jaarnold\Desktop\AlexaSkills\circleCI\node_modules\aws-sdk\lib\sequential_executor.js:105:20)
    at Request.emit (C:\Users\jaarnold\Desktop\AlexaSkills\circleCI\node_modules\aws-sdk\lib\sequential_executor.js:77:10)
    at Request.emit (C:\Users\jaarnold\Desktop\AlexaSkills\circleCI\node_modules\aws-sdk\lib\request.js:683:14)
    at Request.transition (C:\Users\jaarnold\Desktop\AlexaSkills\circleCI\node_modules\aws-sdk\lib\request.js:22:10)
    at AcceptorStateMachine.runTo (C:\Users\jaarnold\Desktop\AlexaSkills\circleCI\node_modules\aws-sdk\lib\state_machine.js:14:12)
    at C:\Users\jaarnold\Desktop\AlexaSkills\circleCI\node_modules\aws-sdk\lib\state_machine.js:26:10
    at Request.<anonymous> (C:\Users\jaarnold\Desktop\AlexaSkills\circleCI\node_modules\aws-sdk\lib\request.js:38:9)
    at Request.<anonymous> (C:\Users\jaarnold\Desktop\AlexaSkills\circleCI\node_modules\aws-sdk\lib\request.js:685:12)
  message: 'Could not unzip uploaded file. Please check your file, then try to upload again.',
  code: 'InvalidParameterValueException',
  time: 2018-06-18T15:09:12.212Z,
  requestId: '8ec20526-7309-11e8-aa20-4fb186ac4f30',
  statusCode: 400,
  retryable: false,
  retryDelay: 65.40106275377198 } 'InvalidParameterValueException: Could not unzip uploaded file. Please check your file, then try to upload again.\n    at Object.extractError (C:\\Users\\jaarnold\\Desktop\\AlexaSkills\\circleCI\\node_modules\\aws-sdk\\lib\\protocol\\json.js:48:27)\n    at Request.extractError (C:\\Users\\jaarnold\\Desktop\\AlexaSkills\\circleCI\\node_modules\\aws-sdk\\lib\\protocol\\rest_json.js:52:8)\n    at Request.callListeners (C:\\Users\\jaarnold\\Desktop\\AlexaSkills\\circleCI\\node_modules\\aws-sdk\\lib\\sequential_executor.js:105:20)\n    at Request.emit (C:\\Users\\jaarnold\\Desktop\\AlexaSkills\\circleCI\\node_modules\\aws-sdk\\lib\\sequential_executor.js:77:10)\n    at Request.emit (C:\\Users\\jaarnold\\Desktop\\AlexaSkills\\circleCI\\node_modules\\aws-sdk\\lib\\request.js:683:14)\n    at Request.transition (C:\\Users\\jaarnold\\Desktop\\AlexaSkills\\circleCI\\node_modules\\aws-sdk\\lib\\request.js:22:10)\n    at AcceptorStateMachine.runTo (C:\\Users\\jaarnold\\Desktop\\AlexaSkills\\circleCI\\node_modules\\aws-sdk\\lib\\state_machine.js:14:12)\n    at C:\\Users\\jaarnold\\Desktop\\AlexaSkills\\circleCI\\node_modules\\aws-sdk\\lib\\state_machine.js:26:10\n    at Request.<anonymous> (C:\\Users\\jaarnold\\Desktop\\AlexaSkills\\circleCI\\node_modules\\aws-sdk\\lib\\request.js:38:9)\n    at Request.<anonymous> (C:\\Users\\jaarnold\\Desktop\\AlexaSkills\\circleCI\\node_modules\\aws-sdk\\lib\\request.js:685:12)'

我尝试从我的计算机和CircleCI部署zip文件,我也尝试使用AWS CLI,所有结果都相同。

我在zip文件和config.json中拥有所需的一切。 我在这里做错了什么?

4 个答案:

答案 0 :(得分:2)

Buffer必须是Buffer

这意味着您必须阅读该文件并将其转换为onChange={event => this.setState({ email:event.target.value })} 对象。

您可以使用fs.readFile()fs.readFileSync()来执行此操作。

答案 1 :(得分:0)

我遇到了这个问题并解决了。

好像您正在压缩zip文件。这就是为什么它无法再次压缩它。

PS:如果您使用的是AWS-S3,请取消选中“ GZIP文件”选项。

答案 2 :(得分:0)

您的ZipFile参数不正确,它必须是缓冲区。尝试更改为:

var fs = require('fs');

var params = {
    FunctionName: 'FunctionName',
    ZipFile: fs.readFileSync('deploy_package.zip')
}

lambda.updateFunctionCode(params, function(err, data) {
    if (err) console.log(err, err.stack);
    else console.log(data);
});

答案 3 :(得分:0)

Node js。使用像

fs.readFile('lambda/function.zip', (err, data) => {
   if (data) {
      console.log(data)
      lambda.createFunction(data);
  }
})