JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1171
  • Score
    100M100P100Q112565F
  • License MIT

Idempotently invoke AWS Lambda functions with Cloudevents

Package Exports

  • @1mill/journal
  • @1mill/journal/dist/index.cjs
  • @1mill/journal/dist/index.module.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@1mill/journal) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@1mill/journal

Idempotently invoke AWS Lambda functions with Cloudevents

Context

https://docs.powertools.aws.dev/lambda/python/latest/utilities/idempotency/#idempotency-request-flow

Install

npm install @1mill/journal
// * index.js
const { Journal } = require('@1mill/journal')

const journal = new Journal({
  name: 'my-journal-db' || process.env.MILL_JOURNAL_NAME,
  table: 'my-collection' || process.env.MILL_JOURNAL_TABLE,
  uri: 'mongodb://...:27017' || process.env.MILL_JOURNAL_URI,
})

export.handler = async (cloudevent, ctx) => {
  // * https://www.jeremydaly.com/reuse-database-connections-aws-lambda/
  ctx.callbackWaitsForEmptyEventLoop = false

  try {
    const { skip } = await journal.entry({ cloudevent })
    if (skip) return // * Already being performed by another lambda

    // * Perform business logic
    // ...
  } catch (err) {
    console.error(err)
    // * Erase entry on business logic failure (e.g. fetch to
    // * third-party API failed)
    await journal.erase({ cloudevent })
    throw new Error(err) // * Requeue event to run again
  }
}