https://github.com/apex/node-apex
Node.js module that makes AWS Lambda's user experience a little nicer using promises.
https://github.com/apex/node-apex
Last synced: 10 months ago
JSON representation
Node.js module that makes AWS Lambda's user experience a little nicer using promises.
- Host: GitHub
- URL: https://github.com/apex/node-apex
- Owner: apex
- License: mit
- Created: 2016-01-31T04:19:30.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-07-11T01:12:59.000Z (over 8 years ago)
- Last Synced: 2024-05-21T07:26:08.352Z (over 1 year ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 279
- Watchers: 10
- Forks: 17
- Open Issues: 4
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
- License: LICENSE
Awesome Lists containing this project
README
# Apex Node.js
Node.js module that makes AWS Lambda's user experience a little nicer.
```js
export default λ(e => 'Hello World')
```
## Installation
```
$ npm install --save apex.js
```
## Features
- return promises
- return results
- actually report uncaught errors (Lambda does not)
## Example
The following example fetches some urls and reports the response status of each. The context and callback are also passed, but are not
shown here.
```js
import axios from 'axios'
import λ from 'apex.js'
import 'babel-polyfill'
export default λ(e => {
console.log('fetching %d urls', e.urls.length)
return Promise.all(e.urls.map(async (url) => {
console.log('fetching %s', url)
return {
status: (await axios.get(url)).status,
url
}
}))
})
```
Without this module it looks something like the following, as Lambda does not try/catch, and the Context
provided has awkward method names that are not idiomatic, or you must use the callback.
```js
import axios from 'axios'
import 'babel-polyfill'
// Vanilla Lambda function.
export default async (e, ctx, cb) => {
console.log('fetching %d urls', e.urls.length)
try {
const res = await Promise.all(e.urls.map(async (url) => {
console.log('fetching %s', url)
return {
status: (await axios.get(url)).status,
url
}
}))
// or ctx.succeed(res);
cb(null, res);
} catch (err) {
// or ctx.fail(err);
cb(err);
}
}
```
## Contributors
- [TJ Holowaychuk](https://github.com/tj)
## Badges


---
> [tjholowaychuk.com](http://tjholowaychuk.com) ·
> GitHub [@tj](https://github.com/tj) ·
> Twitter [@tjholowaychuk](https://twitter.com/tjholowaychuk)