Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(s3-service)!: move to AWS-SDK v3 #216

Merged
merged 2 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about putObject?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I missing something, where is putObject used in this library?

Copy link
Collaborator

@naorpeled naorpeled Feb 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad.
Let's just make sure CI passes before we merge this in

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