Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda Error: Could not unzip uploaded file

I am trying to update the code in my lambda function using the aws-sdk package for node.js. So I wrote the following script to run for deploying the code

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);
});

the problem is that when I run the script I get the following error:

{ 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)'

I have tried deploying the zip file from my computer as well as CircleCI and I have also tried using the AWS CLI, all with the same result.

I have everything I need in the zip file and in the config.json. What could I be doing wrong here?

like image 328
jsteele Avatar asked Jun 18 '18 15:06

jsteele


2 Answers

ZipFile needs to be a Buffer.

That means you have to read the file and convert it to a Buffer object.

You can use fs.readFile() or fs.readFileSync() to do this.

like image 168
Noel Llevares Avatar answered Oct 08 '22 01:10

Noel Llevares


Your ZipFile params is incorrect, it must be a buffer. Try change to :

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);
});
like image 20
Mahdi Ridho Avatar answered Oct 08 '22 01:10

Mahdi Ridho