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.
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); Copy
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 }} Copy
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 }}
Options to configure the idempotency behavior
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
.Example
Similar to decoratoring a handler you can use the decorator on any other function.
Example
See