// 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
Use function wrapper to make your function idempotent.