How to use idempotency with path parameters #3583
-
Hi, I'm building a REST API with usage of API Gateway and want to use idempotency for some routes. Lets consider I have the following route: PUT /notifications/{notificationId} where the body might be
When I now use
it will only use the body for the Idempotency Key, which is the same on different notification ids. How can I build an idempotency key that is composed of several values like body and path? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @tknisch, thanks for opening this discussion. To account for multiple fields, you can use square brackets and list all the fields you want to extract from the payload, in this case it would be For future reference, if you want to test different types of expressions, you can import directly the JMESPath function used by the Idempotency utility and try expressions directly, for example: import { search } from '@aws-lambda-powertools/jmespath';
import { PowertoolsFunctions } from '@aws-lambda-powertools/jmespath/functions';
const extracted = search('[requestContext.http.path, powertools_json(body)]', event, {
customFunctions: new PowertoolsFunctions(),
}) Alternatively, you can also use the online playground in the JMESPath website, they don't have custom functions like Hope this helps! |
Beta Was this translation helpful? Give feedback.
Hi @tknisch, thanks for opening this discussion.
To account for multiple fields, you can use square brackets and list all the fields you want to extract from the payload, in this case it would be
[requestContext.http.path, powertools_json(body)]
or[rawPath, powertools_json(body)]
depending on which field you want to use to get the path.For future reference, if you want to test different types of expressions, you can import directly the JMESPath function used by the Idempotency utility and try expressions directly, for example: