@eggplugin/s3
v1.0.2
Published
AWS S3 plugin for Egg
Downloads
281
Maintainers
Readme
egg-aws-s3
AWS-S3 plugin for Egg.js
NOTE: This plugin just for integrate AWS-S3 into Egg.js, more documentation please visit https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html.
AWS S3 plugin for Egg
Install
$ npm i @eggplugin/s3 --save
Configuration
// {app_root}/config/plugin.js
exports.s3 = {
enable: true,
package: '@eggplugin/s3',
};
see config/config.default.js for more detail.
Simple instance
// {app_root}/config/config.default.js
exports.s3 = {
client: {
accessKeyId: '',
secretAccessKey: '',
endpoint: '',
// ...
},
// load into app, default is open
app: true,
// load into agent, default is close
agent: false,
};
Usage:
(async () => {
// you can access to simple aws s3 instance using app.s3.
const s3 = app.s3;
const data = await s3.listBuckets().promise();
const buckets = data.Buckets.map(item => item.Name);
console.log(buckets);
}).catch(console.error);
Multiple instance
exports.s3 = {
// default configuration for all clients
default: {
// endpoint: '',
// s3ForcePathStyle: '',
// maxRetries: '',
// sslEnabled: '',
// apiVersion: '',
// signatureVersion: '',
// ...
},
clients: {
// clientId, access the client instance by app.s3.get('clientId')
client1: {
accessKeyId: '',
secretAccessKey: '',
endpoint: '',
// ...
},
client2: {
accessKeyId: '',
secretAccessKey: '',
endpoint: '',
// ...
},
// ...
},
// load into app, default is open
app: true,
// load into agent, default is close
agent: false,
};
Usage:
(async () => {
const client1 = app.s3.get('client1');
const client2 = app.s3.get('client2');
const data1 = await client1.listBuckets().promise();
const data2 = await client2.listBuckets().promise();
}).catch(console.error);
Questions & Suggestions
Please open an issue here.