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?
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.
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);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With