Socket
Socket
Sign inDemoInstall

apex-lambda

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    apex-lambda

λ improves AWS Lambda's UX with promises


Version published
Weekly downloads
1
Maintainers
1
Install size
1.97 kB
Created
Weekly downloads
 

Readme

Source

Apex Node.js

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

Example

The following example fetches some urls and reports the response status of each. The context is also passed, but is not shown here.

import λ from 'apex-lambda'
import axios from 'axios'
import 'babel-polyfill'

export default λ(e => {
  console.log('fetching %d urls', e.urls.length)
  return Promise.all(e.urls.map(async function(url){
    console.log('fetching %s', url)
    return {
      status: (await axios.get(url)).status,
      url
    }
  }))
})

Without apex-node 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 function(e, ctx) {
  console.log('fetching %d urls', e.urls.length)

  try {
    const res = await Promise.all(e.urls.map(async function(url){
      console.log('fetching %s', url)
      return {
        status: (await axios.get(url)).status,
        url
      }
    }))

    ctx.succeed(res)
  } catch (err) {
    ctx.fail(err)
  }
}

Contributors

  • TJ Holowaychuk

Badges


tjholowaychuk.com  ·  GitHub @tj  ·  Twitter @tjholowaychuk

Keywords

FAQs

Last updated on 31 Jan 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc