Skip to content

Commit e84d079

Browse files
committed
Upgrade from aws-sdk (v2) to @aws-sdk/client-lambda (v3) #85
1 parent 8b1ed15 commit e84d079

8 files changed

Lines changed: 3304 additions & 651 deletions

dpl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const dpl = require('./lib/index.js');
66
const pkg = require(dpl.utils.getBasepath() + 'package.json');
77
dpl.copyfiles(); // copy required files & dirs
88
if (pkg.files_to_deploy.indexOf('.env') > -1) {
9-
dpl.utils.makeEnvFile(); // github.com/numo-labs/aws-lambda-deploy/issues/31
9+
dpl.utils.makeEnvFile();
1010
}
1111
dpl.install_node_modules(); // install only production node_modules
1212
dpl.zip(); // zip the /dist directory

lib/upload.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
2-
const AWS = require('aws-sdk');
3-
AWS.config.region = process.env.AWS_REGION; // set your Environment Variables...
4-
const lambda = new AWS.Lambda();
2+
const AWS = require("@aws-sdk/client-lambda");
3+
const lambda = new AWS.Lambda({ region: process.env.AWS_REGION });
4+
55
const fs = require('fs'); // so we can read the zip file
66
const assert = require('assert');
77
const utils = require('../lib/utils');
@@ -22,20 +22,15 @@ module.exports = function upload (pkg, callback) {
2222
pkg = PKG
2323
}
2424
const FUNCTION_NAME = utils.functionName(pkg);
25-
// try {
26-
lambda.getFunction({ FunctionName: FUNCTION_NAME }, function (err, data) {
27-
/* istanbul ignore else */
28-
if (err) { // if the function does not already exist we create it.
29-
console.error('upload lambda.getFunction error:', err);
30-
return lambda.createFunction(createParams(pkg), callback);
31-
} else { // otherwise update the *existing* lambda function:
32-
return updateFunction(pkg, callback);
33-
}
34-
});
35-
// } catch (error) {
36-
// console.error(error);
37-
// return callback()
38-
// }
25+
lambda.getFunction({ FunctionName: FUNCTION_NAME }, function (err, data) {
26+
/* istanbul ignore else */
27+
if (err) { // if the function does not already exist we create it.
28+
console.error('upload lambda.getFunction error:', err);
29+
return lambda.createFunction(createParams(pkg), callback);
30+
} else { // otherwise update the *existing* lambda function:
31+
return updateFunction(pkg, callback);
32+
}
33+
});
3934
};
4035

4136
function createParams (pkg) {

package-lock.json

Lines changed: 3281 additions & 621 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"tape": "^4.13.2"
7272
},
7373
"dependencies": {
74-
"aws-sdk": "^2.1550.0",
74+
"@aws-sdk/client-lambda": "^3.504.0",
7575
"env2": "^2.2.2"
7676
},
7777
"semistandard": {

test/000_debug.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ const PKG = require(basepath + 'package.json');
99
const FUNCTION_NAME = utils.functionName(PKG);
1010
console.log('FUNCTION_NAME:', FUNCTION_NAME);
1111

12-
const AWS = require('aws-sdk');
13-
AWS.config.region = process.env.AWS_REGION; // set your Environment Variables...
14-
const lambda = new AWS.Lambda();
12+
const AWS = require("@aws-sdk/client-lambda");
13+
const lambda = new AWS.Lambda({ region: process.env.AWS_REGION });
1514
// console.log(' - - - - - - - - - - - - - - - - - - - - - - ');
1615
// console.log(process);
1716
// console.log(' - - - - - - - - - - - - - - - - - - - - - - ');

test/03_install_node_modules.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ test('install production node_modules only', async function (t) {
99
const distpath = path.normalize(process.env.TMPDIR + 'dist/');
1010
copyfiles();
1111
installnodemodules();
12-
const awspkg = path.resolve(distpath, 'node_modules/aws-sdk/package.json');
12+
const awspkg = path.resolve(distpath, 'node_modules/@aws-sdk/client-lambda/package.json');
1313
const pkg = require(awspkg);
14-
t.deepEqual(pkg.name, 'aws-sdk');
14+
t.deepEqual(pkg.name, '@aws-sdk/client-lambda');
1515
utils.deleteDirContents(distpath, true); // cleanup for next test
1616
t.end();
1717
});

test/05_upload.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ const utils = require('../lib/utils');
88
const fs = require('fs');
99
const path = require('path');
1010

11-
const AWS = require('aws-sdk');
12-
AWS.config.region = process.env.AWS_REGION; // set your Environment Variables...
13-
const lambda = new AWS.Lambda();
11+
const AWS = require("@aws-sdk/client-lambda");
12+
const lambda = new AWS.Lambda({ region: process.env.AWS_REGION });
13+
1414
const basepath = utils.getBasepath();
1515
const PKG = require(basepath + 'package.json');
1616
const FUNCTION_NAME = utils.functionName(PKG);

test/06_lambda_settings.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ const upload = require('../lib/upload');
1010
const utils = require('../lib/utils');
1111

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

0 commit comments

Comments
 (0)