NOTE: THIS REPO IS NOT MAINTAINED The original apex.js package supports Node 4.3 in version 2.
You don't need to use this repository.
This is a separate version of node-apex
designed specifically for the AWS Lambda nodejs4.3
runtime which recommends using the callback
parameter
to complete functions
This can be used in an identical fashion as apex.js for the node 0.10 runtime; it's just designed specifically for the new runtime.
Node.js module that makes AWS Lambda's user experience a little nicer.
export default λ(e => 'Hello World')
$ npm install --save node43apex.js
- return promises
- return results
- actually report uncaught errors (Lambda does not)
The following example fetches some urls and reports the response status of each. The context is also passed, but is not shown here.
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.
import axios from 'axios'
import 'babel-polyfill'
// Vanilla Lambda function.
export default async (e, ctx) => {
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
}
}))
ctx.succeed(res)
} catch (err) {
ctx.fail(err)
}
}
tjholowaychuk.com · GitHub @tj · GitHub @ajcrites · Twitter @tjholowaychuk Twitter @ExplosionPills