Skip to content

Commit

Permalink
Upgrade from aws-sdk (v2) to @aws-sdk/client-lambda (v3) #85
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Feb 3, 2024
1 parent 8b1ed15 commit e84d079
Show file tree
Hide file tree
Showing 8 changed files with 3,304 additions and 651 deletions.
2 changes: 1 addition & 1 deletion dpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const dpl = require('./lib/index.js');
const pkg = require(dpl.utils.getBasepath() + 'package.json');
dpl.copyfiles(); // copy required files & dirs
if (pkg.files_to_deploy.indexOf('.env') > -1) {
dpl.utils.makeEnvFile(); // github.com/numo-labs/aws-lambda-deploy/issues/31
dpl.utils.makeEnvFile();
}
dpl.install_node_modules(); // install only production node_modules
dpl.zip(); // zip the /dist directory
Expand Down
29 changes: 12 additions & 17 deletions lib/upload.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
const AWS = require('aws-sdk');
AWS.config.region = process.env.AWS_REGION; // set your Environment Variables...
const lambda = new AWS.Lambda();
const AWS = require("@aws-sdk/client-lambda");
const lambda = new AWS.Lambda({ region: process.env.AWS_REGION });

const fs = require('fs'); // so we can read the zip file
const assert = require('assert');
const utils = require('../lib/utils');
Expand All @@ -22,20 +22,15 @@ module.exports = function upload (pkg, callback) {
pkg = PKG
}
const FUNCTION_NAME = utils.functionName(pkg);
// try {
lambda.getFunction({ FunctionName: FUNCTION_NAME }, function (err, data) {
/* istanbul ignore else */
if (err) { // if the function does not already exist we create it.
console.error('upload lambda.getFunction error:', err);
return lambda.createFunction(createParams(pkg), callback);
} else { // otherwise update the *existing* lambda function:
return updateFunction(pkg, callback);
}
});
// } catch (error) {
// console.error(error);
// return callback()
// }
lambda.getFunction({ FunctionName: FUNCTION_NAME }, function (err, data) {
/* istanbul ignore else */
if (err) { // if the function does not already exist we create it.
console.error('upload lambda.getFunction error:', err);
return lambda.createFunction(createParams(pkg), callback);
} else { // otherwise update the *existing* lambda function:
return updateFunction(pkg, callback);
}
});
};

function createParams (pkg) {
Expand Down
3,902 changes: 3,281 additions & 621 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"tape": "^4.13.2"
},
"dependencies": {
"aws-sdk": "^2.1550.0",
"@aws-sdk/client-lambda": "^3.504.0",
"env2": "^2.2.2"
},
"semistandard": {
Expand Down
5 changes: 2 additions & 3 deletions test/000_debug.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ const PKG = require(basepath + 'package.json');
const FUNCTION_NAME = utils.functionName(PKG);
console.log('FUNCTION_NAME:', FUNCTION_NAME);

const AWS = require('aws-sdk');
AWS.config.region = process.env.AWS_REGION; // set your Environment Variables...
const lambda = new AWS.Lambda();
const AWS = require("@aws-sdk/client-lambda");
const lambda = new AWS.Lambda({ region: process.env.AWS_REGION });
// console.log(' - - - - - - - - - - - - - - - - - - - - - - ');
// console.log(process);
// console.log(' - - - - - - - - - - - - - - - - - - - - - - ');
Expand Down
4 changes: 2 additions & 2 deletions test/03_install_node_modules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ test('install production node_modules only', async function (t) {
const distpath = path.normalize(process.env.TMPDIR + 'dist/');
copyfiles();
installnodemodules();
const awspkg = path.resolve(distpath, 'node_modules/aws-sdk/package.json');
const awspkg = path.resolve(distpath, 'node_modules/@aws-sdk/client-lambda/package.json');
const pkg = require(awspkg);
t.deepEqual(pkg.name, 'aws-sdk');
t.deepEqual(pkg.name, '@aws-sdk/client-lambda');
utils.deleteDirContents(distpath, true); // cleanup for next test
t.end();
});
6 changes: 3 additions & 3 deletions test/05_upload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const utils = require('../lib/utils');
const fs = require('fs');
const path = require('path');

const AWS = require('aws-sdk');
AWS.config.region = process.env.AWS_REGION; // set your Environment Variables...
const lambda = new AWS.Lambda();
const AWS = require("@aws-sdk/client-lambda");
const lambda = new AWS.Lambda({ region: process.env.AWS_REGION });

const basepath = utils.getBasepath();
const PKG = require(basepath + 'package.json');
const FUNCTION_NAME = utils.functionName(PKG);
Expand Down
5 changes: 2 additions & 3 deletions test/06_lambda_settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ const upload = require('../lib/upload');
const utils = require('../lib/utils');

const basepath = utils.getBasepath();
const AWS = require('aws-sdk');
AWS.config.region = process.env.AWS_REGION; // set your Environment Variables...
const lambda = new AWS.Lambda();
const AWS = require("@aws-sdk/client-lambda");
const lambda = new AWS.Lambda({ region: process.env.AWS_REGION });
let pkg = require(path.resolve(basepath, 'package.json'));
const FUNCTION_NAME = utils.functionName(pkg);

Expand Down

0 comments on commit e84d079

Please sign in to comment.