-
Notifications
You must be signed in to change notification settings - Fork 150
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
Feature request: allow to set idempotency prefix #3515
Comments
Thank you for creating the issue Leo. Note Below are some more information for the implementation in this side of Powertools for AWS. If anyone is interested in picking this up please leave a comment to claim the issue. A maintainer will assign the issue to you and help you with reviewing your PR. Likewise, if you have any questions before starting, feel free to leave a comment below. As part of this work we should add a new Normally this prefix is created automatically by the utility using the AWS Lambda function name (aka the name of the resource) and the name of the function in your code being made idempotent (i.e. With this change, customers should be able to specify their own prefix. When doing this, the customer-provided prefix will be used instead of the one generated by the utility. Customers should be able to do this when decorating a function, making it idempotent via Middy.js middleware, or higher-order function. Below some examples of how the DX would look like after the change. const persistenceStore = new DynamoDBPersistenceLayer({
tableName: 'idempotencyTableName',
});
const processPayment = makeIdempotent(
async (paymentProps) => {
// ... process your payload
return {
message: 'success',
statusCode: 200,
};
},
{
persistenceStore,
keyPrefix: 'some_custom_value', // <-- new parameter
}
);
export const handler = async (event) => {
// ... do something with the event
return processPayment({
customerId: event.customerId,
amount: event.amount
});
};
// OR
const config = new IdempotencyConfig({});
class MyLambda implements LambdaInterface {
@idempotent({
persistenceStore,
config,
keyPrefix: 'some_custom_value', // <-- new parameter
})
public async handler(_event, _context) {
// ... process your event
return {
message: 'success',
statusCode: 200,
};
}
}
const defaultLambda = new MyLambda();
export const handler = defaultLambda.handler.bind(defaultLambda);
// OR
export const handler = middy(
async (event) => {
// ... process your event
).use(
makeHandlerIdempotent({
persistenceStore,
keyPrefix: 'some_custom_value', // <-- new parameter
})
); To do this, we should follow this high level plan:
Note that there might be other parts of the code to touch that I might have forgotten, make sure to take a closer look at the current implementation before starting. |
Hi, I'd like to help with this issue. Could you please assign it to me? |
Absolutely! And nice to see you back here, looking forward to work with you on the PR! |
This issue is now closed. Please be mindful that future comments are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so. |
This is now released under v2.15.0 version! |
Use case
Original issue: aws-powertools/powertools-lambda-python#5897
The prefix to the Idempotency key is hardcoded to force a fully qualified name based on the location of the function that uses the decorator. There is no simple way of modifying this behavior in order to make that prefix some static value.
https://github.com/aws-powertools/powertools-lambda-typescript/blob/main/packages/idempotency/src/persistence/BasePersistenceLayer.ts#L55
This makes the Idempotency susceptible to future code refactoring. To prevent duplicate handling you can either
Solution/User Experience
A solution is to provide a way to override the key prefix on the
makeIdempotent
function. An optional argument likekeyPrefix
that allows a user to provided a fix string. This would allow freedom of refactoring (or even have multiple functions that are controlled by the same idempotency key space).Considerations:
Alternative solutions
Python implementation + documentation: https://github.com/aws-powertools/powertools-lambda-python/pull/5898
Acknowledgment
Future readers
Please react with 👍 and your use case to help us understand customer demand.
The text was updated successfully, but these errors were encountered: