Skip to content

Commit

Permalink
feat(s3-service)!: move to AWS-SDK v3 (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewBarba committed Mar 9, 2023
1 parent e78a26b commit a99b8bb
Show file tree
Hide file tree
Showing 7 changed files with 8,342 additions and 5,809 deletions.
1 change: 0 additions & 1 deletion __tests__/download.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const fs = require('fs') // Require Node.js file system
// Require Sinon.js library
const sinon = require('sinon')

const AWS = require('aws-sdk') // AWS SDK (automatically available in Lambda)
const S3 = require('../lib/s3-service') // Init S3 Service

// Init API instance
Expand Down
3 changes: 0 additions & 3 deletions __tests__/getLink.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ const delay = ms => new Promise(res => setTimeout(res, ms))
// Require Sinon.js library
const sinon = require('sinon')

const AWS = require('aws-sdk') // AWS SDK (automatically available in Lambda)
// AWS.config.credentials = new AWS.SharedIniFileCredentials({profile: 'madlucas'})

const S3 = require('../lib/s3-service') // Init S3 Service

// Init API instance
Expand Down
1 change: 0 additions & 1 deletion __tests__/responses.unit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const sinon = require('sinon') // Require Sinon.js library
const AWS = require('aws-sdk') // AWS SDK (automatically available in Lambda)
const S3 = require('../lib/s3-service') // Init S3 Service
const { gzipSync, brotliCompressSync, deflateSync } = require('zlib')

Expand Down
3 changes: 0 additions & 3 deletions __tests__/sendFile.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ const fs = require('fs') // Require Node.js file system
// Require Sinon.js library
const sinon = require('sinon')

const AWS = require('aws-sdk') // AWS SDK (automatically available in Lambda)
// AWS.config.credentials = new AWS.SharedIniFileCredentials({profile: 'madlucas'})

const S3 = require('../lib/s3-service'); // Init S3 Service

// Init API instance
Expand Down
36 changes: 34 additions & 2 deletions lib/s3-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,39 @@
*/

// Require AWS SDK
const AWS = require('aws-sdk'); // AWS SDK
const { S3Client, GetObjectCommand } = require('@aws-sdk/client-s3'); // AWS SDK
const { getSignedUrl } = require('@aws-sdk/s3-request-presigner');

// Export
module.exports = new AWS.S3();
exports.client = new S3Client();

exports.getObject = (params) => {
const cmd = new GetObjectCommand(params);
const promise = this.client.send(cmd);
return {
promise: () => promise,
};
};

exports.getSignedUrl = async (
type,
{ Expires, ...params },
callback = () => {}
) => {
let command;
switch (type) {
case 'getObject':
command = new GetObjectCommand(params);
break;
default:
throw new Error('Invalid command type');
}
return getSignedUrl(this.client, command, { expiresIn: Expires })
.then((url) => {
callback(null, url);
return url;
})
.catch((err) => {
callback(err);
});
};
Loading

0 comments on commit a99b8bb

Please sign in to comment.