Skip to content

Feedback wanted: support for Redis in Idempotency #3183

Open
@dreamorosi

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

Future readers

Please react with 👍 and your use case to help us understand customer demand.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    discussingThe issue needs to be discussed, elaborated, or refinedfeature-requestThis item refers to a feature request for an existing or new utilityidempotencyThis item relates to the Idempotency Utilityneed-customer-feedbackRequires more customers feedback before making or revisiting a decision

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions