@eggplugin/s3

1.0.2 • Public • Published

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.

NPM version build status Test coverage David deps Known Vulnerabilities npm download

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.

License

MIT

Package Sidebar

Install

npm i @eggplugin/s3

Weekly Downloads

110

Version

1.0.2

License

MIT

Unpacked Size

7.47 kB

Total Files

7

Last publish

Collaborators

  • fuxingzhang