UNPKG

@aws-lambda-powertools/idempotency

Version:

The idempotency package for the Powertools for AWS Lambda (TypeScript) library. It provides options to make your Lambda functions idempotent and safe to retry.

36 lines 1.39 kB
import type { AnyFunction, ItempotentFunctionOptions } from './types/IdempotencyOptions.js'; /** * Use function wrapper to make your function idempotent. * @example * ```ts * // this is your processing function with an example record { transactionId: '123', foo: 'bar' } * const processRecord = (record: Record<string, unknown>): any => { * // you custom processing logic * return result; * }; * * // we use wrapper to make processing function idempotent with DynamoDBPersistenceLayer * const processIdempotently = makeIdempotent(processRecord, { * persistenceStore: new DynamoDBPersistenceLayer() * dataKeywordArgument: 'transactionId', // keyword argument to hash the payload and the result * }); * * export const handler = async ( * _event: EventRecords, * _context: Context * ): Promise<void> => { * for (const record of _event.records) { * const result = await processIdempotently(record); * // do something with the result * } * * return Promise.resolve(); * }; * * @param fn - the function to make idempotent * @param options - the options to configure the idempotency behavior * ``` */ declare function makeIdempotent<Func extends AnyFunction>(fn: Func, options: ItempotentFunctionOptions<Parameters<Func>>): (...args: Parameters<Func>) => ReturnType<Func>; export { makeIdempotent }; //# sourceMappingURL=makeIdempotent.d.ts.map