Skip to content

Conversation

guillemcomerma
Copy link
Contributor

Summary

Fixes documentation error where dataKeywordArgument is referenced but doesn't exist in the type definitions.

Changes

Please provide a summary of what's being changed

  • Replaced dataKeywordArgument references with config.eventKeyJmesPath in documentation

  • Removed unused dataKeywordArgument reference from test file

Please add the issue number below, if no issue is present the PR might get blocked and not be reviewed

Issue number: closes #4533


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

Copy link

boring-cyborg bot commented Sep 23, 2025

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #typescript channel on our Powertools for AWS Lambda Discord: Invite link

Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR!

This bit of documentation is quite old and I think we can improve it significantly.

The suggestion you made is correct, but I believe we should explain better when to use eventKeyJmesPath and when dataIndexArgument.

I'd suggest to update the documentation to something close to this:

/**
 * Function wrapper to make any function idempotent.
 *
 * The `makeIdempotent` function is a higher-order function that takes another function and returns a new version of that function with idempotency behavior.
 * This means that if the function is called multiple times with the same input, it will return the same result without re-executing the original function logic.
 *
 * By default, the entire payload (first argument) is hashed to create a unique key for idempotency. However you can customize this behavior by either using a subset
 * of the payload using {@link IdempotencyConfig.eventKeyJmesPath | `eventKeyJmesPath`} from {@link IdempotencyConfig | `IdempotencyConfig`} or specifying a different
 * function argument to hash using {@link ItempotentFunctionOptions.dataIndexArgument | `dataIndexArgument`} in the options.
 *
 * **Using a subset of the payload**
 *
 * @example
 * ```ts
 * import {
 *   IdempotencyConfig,
 *   makeIdempotent,
 * } from '@aws-lambda-powertools/idempotency';
 * import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb';
 *
 * const persistenceStore = new DynamoDBPersistenceLayer({
 *   tableName: 'my-idempotency-table',
 * });
 *
 * // function to be made idempotent
 * const processRecord = (record: Record<string, unknown>): unknown => {
 *   // ... you custom processing logic
 *   return result;
 * };
 *
 * // create the idempotent version of the function
 * const processIdempotently = makeIdempotent(processRecord, {
 *   persistenceStore,
 *   config: new IdempotencyConfig({
 *     eventKeyJmesPath: 'transactionId', // use only the transactionId field from the record as idempotency key
 *   }),
 * });
 *
 * export const handler = async (
 *   event: { records: Record<string, unknown>[] },
 * ) => {
 *   for (const record of event.records) {
 *     // use the idempotent function
 *     const result = await processIdempotently(record);
 *     // ... do something with the result
 *   }
 * };
 * ```
 *
 * **Specifying a different function argument to hash**
 *
 * @example
 * ```ts
 * import {
 *   IdempotencyConfig,
 *   makeIdempotent,
 * } from '@aws-lambda-powertools/idempotency';
 * import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb';
 *
 * const persistenceStore = new DynamoDBPersistenceLayer({
 *   tableName: 'my-idempotency-table',
 * });
 *
 * // function to be made idempotent
 * const processRecord = (
 *   record: Record<string, unknown>,
 *   userId: string
 * ): unknown => {
 *   // ... your custom processing logic
 *   return result;
 * }
 *
 * // create the idempotent version of the function
 * const processIdempotently = makeIdempotent(processRecord, {
 *   persistenceStore,
 *   dataIndexArgument: 1, // hash the second argument (userId) instead of the first (record)
 * });
 *
 * export const handler = async (
 *   event: { records: Record<string, unknown>[], userId: string },
 * ) => {
 *   for (const record of event.records) {
 *     const userId = event.userId;
 *     // use the idempotent function
 *     const result = await processIdempotently(record, userId);
 *     // ... do something with the result
 *   }
 * };
 * ```
 *
 * @param fn - the function to make idempotent
 * @param options - the options to configure the idempotency behavior
 */

@pull-request-size pull-request-size bot added size/M PR between 30-99 LOC and removed size/XS PR between 0-9 LOC labels Sep 24, 2025
@guillemcomerma
Copy link
Contributor Author

Thank you for your feedback @dreamorosi
I like how you've structured this to clearly explain the distinction between eventKeyJmesPath and dataIndexArgument
I've incorporated your suggestions with few refinements

Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for improving this section of the docs and addressing the review feedback, really appreciate it!

Copy link

@sdangol sdangol merged commit 3d1255c into aws-powertools:main Sep 24, 2025
34 checks passed
Copy link

boring-cyborg bot commented Sep 24, 2025

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

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

Labels

idempotency This item relates to the Idempotency Utility size/M PR between 30-99 LOC tests PRs that add or change tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs: Fix documentation error: dataKeywordArgument should be replaced by dataIndexArgument use case or removed to avoid confusion

3 participants