Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sholladay/hapi-s3
Use Amazon S3 in your hapi server
https://github.com/sholladay/hapi-s3
aws hapi plugin s3 server storage
Last synced: 14 days ago
JSON representation
Use Amazon S3 in your hapi server
- Host: GitHub
- URL: https://github.com/sholladay/hapi-s3
- Owner: sholladay
- License: mpl-2.0
- Created: 2017-11-07T04:43:26.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-01-13T18:51:44.000Z (almost 5 years ago)
- Last Synced: 2024-04-14T08:31:04.665Z (7 months ago)
- Topics: aws, hapi, plugin, s3, server, storage
- Language: JavaScript
- Homepage:
- Size: 20.5 KB
- Stars: 4
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# hapi-s3 [![Build status for hapi S3](https://travis-ci.com/sholladay/hapi-s3.svg?branch=master "Build Status")](https://travis-ci.com/sholladay/hapi-s3 "Builds")
> Use [Amazon S3](https://aws.amazon.com/s3/) in your [hapi](https://hapijs.com/) server
Provides an instance of [Scube](https://github.com/sholladay/scube), a thin wrapper around the S3 client from the [AWS SDK](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/index.html), so you can interact with S3 programmatically. It is available at `request.server.s3` in route handlers.
## Why?
- Easily implement streaming uploads / downloads.
- Memory efficient, with one instance of the [AWS SDK](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/index.html) per server.
- Loads credentials explicitly.## Install
```sh
npm install hapi-s3
```## Usage
Register the plugin on your server to make `request.server.s3` available in route handlers.
```js
const hapi = require('@hapi/hapi');
const s3 = require('hapi-s3');const server = hapi.server();
const init = async () => {
await server.register({
plugin : s3,
options : {
bucket : 'my-bucket',
publicKey : process.env.AWS_ACCESS_KEY_ID,
secretKey : process.env.AWS_SECRET_ACCESS_KEY
}
});
server.route({
method : 'GET',
path : '/',
async handler(request) {
const { s3 } = request.server;
const buckets = await s3.listBuckets();
return buckets;
}
});
await server.start();
console.log('Server ready:', server.info.uri);
};init();
```## API
Please see [Scube](https://github.com/sholladay/scube) for details on the `s3` object.
### Plugin options
Type: `object`
The options are passed to `new Scube()` to configure the S3 client. See [Scube](https://github.com/sholladay/scube) for details on the available options, such as `bucket`, `region`, and others.
### Decorations
For convenience, this plugin adds the following API to the hapi server instance.
#### server.s3
An instance of [Scube](https://github.com/sholladay/scube), a thin wrapper around the S3 client from the [AWS SDK](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/index.html). This is available as `request.server.s3` inside of route handlers.
## Related
- [scube](https://github.com/sholladay/scube) - Manage your [S3](https://aws.amazon.com/s3/) buckets
## Contributing
See our [contributing guidelines](https://github.com/sholladay/hapi-s3/blob/master/CONTRIBUTING.md "Guidelines for participating in this project") for more details.
1. [Fork it](https://github.com/sholladay/hapi-s3/fork).
2. Make a feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. [Submit a pull request](https://github.com/sholladay/hapi-s3/compare "Submit code to this project for review").## License
[MPL-2.0](https://github.com/sholladay/hapi-s3/blob/master/LICENSE "License for hapi-s3") © [Seth Holladay](https://seth-holladay.com "Author of hapi-s3")
Go make something, dang it.