node-apex

Node.js module that makes AWS Lambda's user experience a little nicer using promises.

  • 所有者: apex/node-apex
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

Apex Node.js

Node.js module that makes AWS Lambda's user experience a little nicer.

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.

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.

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

Badges



tjholowaychuk.com  · 
GitHub @tj  · 
Twitter @tjholowaychuk

主要指標

概覽
名稱與所有者apex/node-apex
主編程語言JavaScript
編程語言JavaScript (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2016-01-31 04:19:30
推送於2017-07-11 01:12:59
最后一次提交2017-07-10 18:12:58
發布數2
最新版本名稱v1.1.0 (發布於 2016-01-31 11:51:37)
第一版名稱v1.0.0 (發布於 2016-01-30 20:21:18)
用户参与
星數280
關注者數9
派生數14
提交數14
已啟用問題?
問題數6
打開的問題數3
拉請求數2
打開的拉請求數1
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?