-
Notifications
You must be signed in to change notification settings - Fork 444
Open
Labels
feature-requestfeature requestfeature requesttriagePending triage from maintainersPending triage from maintainers
Description
Use case
Customers are using the Powertools Idempotency utility for caching purposes. Idempotency is a specific implementation that includes a "caching" mechanism via the storage provider classes. Idempotency is a particular use case, and there is inbuilt functionality for dealing with the records in a specific way which I feel is dangerous for caching use cases.
Solution/User Experience
from aws_lambda_powertools.utilities.caching import (
DynamoDBPersistenceLayer,
Cache,
)
table = os.getenv("CACHE_TABLE", "")
persistence_layer = DynamoDBPersistenceLayer(table_name=table)
cache = Cache(persistence_store=peristsance_layer)
my_ttl = 300
def lambda_handler(event: dict, context: LambdaContext):
try:
previous_value = cache.get(event.order_id, "default_value")
payment: Payment = create_subscription_payment(event, previous_value)
cache.set(order_id, payment.detail, my_ttl)
return {
"payment_id": payment.payment_id,
"message": "success",
"statusCode": 200,
}
except Exception as exc:
raise PaymentError(f"Error creating payment {str(exc)}")
def create_subscription_payment(event: dict) -> Payment:
return Payment(**event)
Alternative solutions
Acknowledgment
- This feature request meets Powertools for AWS Lambda (Python) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Java, TypeScript, and .NET
TonySherman
Metadata
Metadata
Assignees
Labels
feature-requestfeature requestfeature requesttriagePending triage from maintainersPending triage from maintainers
Type
Projects
Status
Triage