-
Notifications
You must be signed in to change notification settings - Fork 406
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: Idempotency prefix is susceptible to refactoring #5897
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Hi @lbustelo, thank you for opening the issue. I'm not against adding this feature as long as we add a clear disclaimer to the docs / API docs explaining that changing this value on existing functions will void the idempotency. Regarding the implementation, I'd agree with your suggestion of replacing the full prefix. Basically you'd either let us decide the prefix, or take full control of it. Will wait for other maintainers to weigh in before adding it to the backlog. |
Hey @lbustelo , thanks for opening a feature request. This would certainly help during refactoring and also give more freedom to pick your own key. I agree with @dreamorosi to leave it to user completely once they want to customize it. That will create clear responsibility boundary between library authors and users. |
Hi @lbustelo! Thanks for opening this issue. I'm not very happy with the name of the
I agree with letting the customer decide what they want as a prefix and not making assumptions here. PR: #5898 The experience might be like: Decorating standalone functionsimport os
from dataclasses import dataclass
from aws_lambda_powertools.utilities.idempotency import (
DynamoDBPersistenceLayer,
IdempotencyConfig,
idempotent_function,
)
from aws_lambda_powertools.utilities.typing import LambdaContext
table = os.getenv("IDEMPOTENCY_TABLE", "")
dynamodb = DynamoDBPersistenceLayer(table_name=table)
config = IdempotencyConfig(event_key_jmespath="order_id") # see Choosing a payload subset section
@dataclass
class OrderItem:
sku: str
description: str
@dataclass
class Order:
item: OrderItem
order_id: int
@idempotent_function(
data_keyword_argument="order",
config=config,
persistence_store=dynamodb,
idempotency_key_custom_prefix="my_custom_prefix",
)
def process_order(order: Order):
return f"processed order {order.order_id}"
def lambda_handler(event: dict, context: LambdaContext):
config.register_lambda_context(context)
order_item = OrderItem(sku="fake", description="sample")
order = Order(item=order_item, order_id=1)
process_order(order=order) Decorating the Lambda handlerfrom aws_lambda_powertools.utilities.idempotency import (
DynamoDBPersistenceLayer,
idempotent,
)
from aws_lambda_powertools.utilities.typing import LambdaContext
persistence_layer = DynamoDBPersistenceLayer(table_name="ddbidempotency")
@idempotent(persistence_layer=persistence_layer, idempotency_key_custom_prefix="my_other_custom_prefix")
def lambda_handler(event: dict, context: LambdaContext):
return "a" |
On second thought, it doesn't make much sense to add |
|
This is now released under 3.5.0 version! |
Use case
Problem:
Using aws-lambda-powertools==3.4.1
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.
powertools-lambda-python/aws_lambda_powertools/utilities/idempotency/base.py
Line 106 in bb24814
This makes the Idempotency susceptible to future code refactoring. To prevent duplicate handling you can either
@idempotent_function
Solution/User Experience
A solution is to provide a way to override the key prefix on the
@idempotent_function
function. An optional argument likeidempotency_key_prefix
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:
#<hash of arguments>
would stay intactAlternative solutions
Acknowledgment
The text was updated successfully, but these errors were encountered: