Skip to content

Instantly share code, notes, and snippets.

@jeremypruitt
Created September 3, 2015 04:22
Show Gist options
  • Save jeremypruitt/dc39015f0bb5fc65e7fd to your computer and use it in GitHub Desktop.
Save jeremypruitt/dc39015f0bb5fc65e7fd to your computer and use it in GitHub Desktop.
var req = https.request(options, function(res) {
console.log("statusCode: ", res.statusCode);
//console.log("headers: ", res.headers);
var data = [], data_length = 0;
res.on('data', function(d) {
data.push(d);
data_length += d.length;
}).on('end', function() {
var buf = new Buffer(data_length);
for (var i=0, len = data.length, pos = 0; i < len; i++) {
data[i].copy(buf, pos);
pos += data[i].length;
}
var zip = new AdmZip(buf);
var new_zip = new AdmZip();
var zipEntries = zip.getEntries();
zipEntries.forEach(function(zipEntry) {
file_name = zipEntry.entryName;
new_file_name = file_name.substring(file_name.indexOf("/") + 1);
if (new_file_name === "") {
return
} else {
console.log(file_name+" -> "+new_file_name);
new_zip.addFile(new_file_name, new Buffer(zip.readFile(zipEntry)), "entry comment goes here");
}
});
var params = {
FunctionName: 'arn:aws:lambda:us-east-1:REMOVED:function:REMOVED',
ZipFile: new_zip.toBuffer()
};
lambda.updateFunctionCode(params, function(err, data) {
if (err) console.log(err, err.stack);
context.done(null, 'Function Finished!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment