Use this decorator to make your lambda handler itempotent. You need to provide a peristance layer to store the idempotency information. At the moment we only support DynamodbPersistenceLayer.

import {
DynamoDBPersistenceLayer,
idempotentLambdaHandler
} from '@aws-lambda-powertools/idempotency';
import type { LambdaInterface } from '@aws-lambda-powertools/commons/types';

class MyLambdaFunction implements LambdaInterface {
⁣@idempotent({ persistenceStore: new DynamoDBPersistenceLayer() })
async handler(event: unknown, _context: unknown) {
return "Hello World";
}
}
export myLambdaHandler new MyLambdaFunction();
export const handler = myLambdaHandler.handler.bind(myLambdaHandler);

Similar to decoratoring a handler you can use the decorator on any other function.

import {
DynamoDBPersistenceLayer,
idempotentFunction
} from '@aws-lambda-powertools/idempotency';
import type { LambdaInterface } from '@aws-lambda-powertools/commons/types';

class MyClass implements LambdaInterface {
public async handler(event: unknown, _context: unknown) {
for(const record of event.records){
await this.process(record);
}
}

⁣@idemptent({ persistenceStore: new DynamoDBPersistenceLayer() })
public async process(record: Record<stiring, unknown>) {
// do some processing
}
}