https://github.com/svozza/readert-aws-example
A simple example of how to use monad transformers to perform side effects that access AWS
https://github.com/svozza/readert-aws-example
Last synced: 11 months ago
JSON representation
A simple example of how to use monad transformers to perform side effects that access AWS
- Host: GitHub
- URL: https://github.com/svozza/readert-aws-example
- Owner: svozza
- Created: 2020-10-21T07:38:59.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-10-22T08:06:18.000Z (over 5 years ago)
- Last Synced: 2025-01-24T12:13:17.260Z (over 1 year ago)
- Language: JavaScript
- Size: 29.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## ReaderT-aws-example
The node.js script in `index.js` uses the `ReaderT` monad transformer (from
[Crocks](https://crocks.dev/docs/crocks/ReaderT.html)) to pass dependencies to the effectful functions.
The monad stack comprises the [Reader](https://crocks.dev/docs/crocks/Reader.html) and [Async](https://crocks.dev/docs/crocks/Async.html)
monads. The exported `run` function will retrieve the first 5 objects in a specified S3 Bucket.
### To use
Ensure you have these variables set in your shell
```bash
export AWS_REGION=
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
```
Then consume the `run` function
```js
const {run} = require('index');
const log = label => console.log.bind(console, label + ':');
// using Crocks Async ADT
run('myBucket').fork(log('rej'), log('res'));
// using async / await
const objects = await run('myBucket').toPromise();
console.log(objects);
```
### Running unit tests
```bash
npm test
```