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.

83 lines 3.08 kB
import type { CachePersistenceOptions } from '../types/CachePersistence.js'; import { BasePersistenceLayer } from './BasePersistenceLayer.js'; import { IdempotencyRecord } from './IdempotencyRecord.js'; /** * Valkey and Redis OOS-compatible persistence layer for idempotency records. * * This class uses a cache client to write and read idempotency records. It supports any client that * implements the {@link CacheClient | `CacheClient`} interface. * * There are various options to configure the persistence layer, such as attribute names for storing * status, expiry, data, and validation keys in the cache. * * You must provide your own connected client instance by passing it through the `client` option. * * See the {@link https://docs.powertools.aws.dev/lambda/typescript/latest/features/idempotency/ Idempotency documentation} * for more details on the configuration and usage patterns. * * **Using Valkey Glide Client** * * @example * ```ts * import { GlideClient } from '@valkey/valkey-glide'; * import { CachePersistenceLayer } from '@aws-lambda-powertools/idempotency/cache'; * * const client = await GlideClient.createClient({ * addresses: [{ * host: String(process.env.CACHE_ENDPOINT), * port: Number(process.env.CACHE_PORT), * }], * useTLS: true, * requestTimeout: 2000 * }); * * const persistence = new CachePersistenceLayer({ * client, * }); * * // ... your function handler here * ``` * * **Using Redis Client** * * @example * ```ts * import { createClient } from '@redis/client'; * import { CachePersistenceLayer } from '@aws-lambda-powertools/idempotency/cache'; * * const client = await createClient({ * url: `rediss://${process.env.CACHE_ENDPOINT}:${process.env.CACHE_PORT}`, * username: 'default', * }).connect(); * * const persistence = new CachePersistenceLayer({ * client, * }); * * // ... your function handler here * ``` * * @category Persistence Layer */ declare class CachePersistenceLayer extends BasePersistenceLayer { #private; constructor(options: CachePersistenceOptions); /** * Deletes the idempotency record associated with a given record from the persistence store. * * This function is designed to be called after a Lambda handler invocation has completed processing. * It ensures that the idempotency key associated with the record is removed from the cache to * prevent future conflicts and to maintain the idempotency integrity. * * Note: it is essential that the idempotency key is not empty, as that would indicate the Lambda * handler has not been invoked or the key was not properly set. * * @param record */ protected _deleteRecord(record: IdempotencyRecord): Promise<void>; protected _putRecord(record: IdempotencyRecord): Promise<void>; protected _getRecord(idempotencyKey: string): Promise<IdempotencyRecord>; protected _updateRecord(record: IdempotencyRecord): Promise<void>; } export { CachePersistenceLayer }; //# sourceMappingURL=CachePersistenceLayer.d.ts.map