notonthehighstreet/node-lambda-events

View on GitHub
examples/S3.md

Summary

Maintainability
Test Coverage
### Simple S3 Example

The below example demonstrates the processing of an S3 event.

```javascript
import { S3 } from 'node-lambda-events';
import AWS from 'aws-sdk';

const REGION = process.env.AWS_REGION;

class S3EventReceiver extends S3 {
  async each(record) {
    const { Body } = await this.fetch();
    return this.push(Body);
  }

  fetch() {
    return new Promise((resolve, reject) => {
      const s3 = new AWS.S3({ region: REGION });
      s3.getObject(this.location, (err, data) => {
        if (err) {
          reject(err);
        } else {
          resolve(data);
        }
      });
    })
  }

  push(data) {
    // DO SOMETHING!
  }
}

export default S3.wrap(S3EventReceiver);
```