An open API service indexing awesome lists of open source software.

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

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
```