Idempotently invoke AWS Lambda functions with Cloudevents.
npm install @1mill/journal
// * index.js
import { Locker, withIdempotency } from '@1mill/journal'
const locker = new Locker({
name: 'my-locker-db-name',
table: 'my-collection-name',
uri: 'mongodb://...:27017/',
})
const func = (cloudevent, ctx) => {
console.log('Running once: ', cloudevent)
return { cloudevent }
}
export const handler = async (cloudevent, ctx) => withIdempotency(cloudevent, ctx, { func, locker })
Name | Required | Types | Default | Environment | Description |
---|---|---|---|---|---|
expireAfterSeconds | number | 86400 (1 day) |
MILL_JOURNAL_EXPIRE_AFTER_SECONDS |
How long a Cloudevent idempotency key will keep-alive | |
name | yes | string | MILL_JOURNAL_NAME |
The name of the database itself | |
options | object | {} |
Options pass to the database client | ||
table | yes | string | MILL_JOURNAL_TABLE |
The name of the table inside the database | |
uri | yes | string | MILL_JOURNAL_URI |
URI to connect to database |
Name | Required | Types | Default | Environment | Description |
---|---|---|---|---|---|
func | yes | function | The function containing business logic that will run | ||
locker | yes | Locker |
The Locker in which idempotency keys will be checked against |