Feedback wanted: support for Redis in Idempotency #3183
Description
Use case
The Idempotency utility currently supports only DynamoDB as persistence layer.
With AWS announcing Amazon ElastiCache for Valkey, we would like to understand if there's demand for the Idempotency utility in Powertools for AWS Lambda (TypeScript) supporting Redis-compatible persistence layers.
Important
We are opening this issue to gauge demand for this feature. If you're interested please leave a 👍 under this issue. If you'd like, consider also leaving a comment with your use case. If you are not comfortable sharing details in public, you can also do so by emailing us at aws-powertools-maintainers@amazon.com with your work email.
Solution/User Experience
From a customer perspective, using ElastiCache as persistence layer should be as transparent as possible and the DX should look the same as today except that instead of instantiating a DynamoDBPersistenceLayer
, you'd be instantiating an ElastiCachePersistenceLayer
(Name TBD).
Below a high level example of how it'd look like:
import { randomUUID } from 'node:crypto';
import { makeIdempotent } from '@aws-lambda-powertools/idempotency';
import { ElastiCachePersistenceLayer } from '@aws-lambda-powertools/idempotency/elasticache';
import type { Context } from 'aws-lambda';
import type { Request, Response, SubscriptionResult } from './types.js';
const persistenceStore = new ElastiCachePersistenceLayer({
url: 'redis://<cache-name>.serverless.<region-id>.cache.amazonaws.com:6379',
// password: presignedUrl, (optional) - default is RBAC with serverless mode
// username: 'default', (optional) - default is RBAC with serverless mode
// clientConfig: {} (optional) - object to configure underlying client
});
const createSubscriptionPayment = async (
event: Request
): Promise<SubscriptionResult> => {
// ... create payment
return {
id: randomUUID(),
productId: event.productId,
};
};
export const handler = makeIdempotent(
async (event: Request, _context: Context): Promise<Response> => {
try {
const payment = await createSubscriptionPayment(event);
return {
paymentId: payment.id,
message: 'success',
statusCode: 200,
};
} catch (error) {
throw new Error('Error creating payment');
}
},
{
persistenceStore,
}
);
Note
The API shown above is just for illustration purposes and might be different in the final implementation. We however welcome comments and feedback if you have any.
Alternative solutions
The feature is already available in Powertools for AWS Lambda (Python), so we should use that as reference.
Acknowledgment
- This feature request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Assignees
Labels
Type
Projects
Status
Ideas
Activity