-
Notifications
You must be signed in to change notification settings - Fork 175
docs(idempotency): fix dataKeywordArgument reference and remove unused test code #4537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs(idempotency): fix dataKeywordArgument reference and remove unused test code #4537
Conversation
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
There was a problem hiding this 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
*/
Thank you for your feedback @dreamorosi |
There was a problem hiding this 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!
|
Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience! |
Summary
Fixes documentation error where
dataKeywordArgument
is referenced but doesn't exist in the type definitions.Changes
Replaced
dataKeywordArgument
references withconfig.eventKeyJmesPath
in documentationRemoved unused
dataKeywordArgument
reference from test fileIssue 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.