powertools-lambda-typescript icon indicating copy to clipboard operation
powertools-lambda-typescript copied to clipboard

Feature request: ability to specify JMESPath custom functions for Idempotency

Open dreamorosi opened this issue 4 months ago • 2 comments

Use case

When working with the JMESPath expressions, the Idempotency utility uses some custom functions (i.e. powertools_json()) that extend the JMESPath built-in functions. This allows customers to work with some complex types that are common when working with AWS payloads.

The underlying JMESPath utility used by Idempotency however allows for further customization by allowing customers to set additional custom functions in addition or instead of the Powertools-provided ones.

It would be great if customers were able to pass their own subclass of Functions or PowertoolsFunctions when using the Idempotency utility.

Solution/User Experience

Currently the Idempotency utility creates its own instance of the PowertoolsFunctions class when instantiating the IdempotencyConfig class. This allows the various components of the utility to reuse it across the implementation.

The setting could be exposed to customers by adding a new option to the IdempotencyConfig class/object:

import { makeIdempotent, IdempotencyConfig } from '@aws-lambda-powertools/idempotency';
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb';

const persistenceStore = new DynamoDBPersistenceLayer({
  tableName: 'idempotencyTableName',
});

class MyFancyFunctions extends PowertoolsFunctions {
  @Functions.signature({
    argumentsSpecs: [['string']],
  })
  public funcMyFancyFunction(value: string): JSONValue {
    return JSON.parse(value);
  }
}

export const handler = makeIdempotent(async () => true, {
  persistenceStore,
  config: new IdempotencyConfig({
    eventKeyJmespath: 'my_fancy_function(body).["user", "productId"]',
    jmesPathOptions: new MyFancyFunctions(), // passed as part of the idempotency configs
  }),
});

Alternative solutions

No response

Acknowledgment

Future readers

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

dreamorosi avatar Apr 16 '24 12:04 dreamorosi