-
Notifications
You must be signed in to change notification settings - Fork 433
docs(idempotency): improve navigation, wording, and new section on guarantees #4613
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
Merged
leandrodamascena
merged 42 commits into
aws-powertools:develop
from
heitorlessa:docs/idempotency-guarantees
Jul 25, 2024
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
8b4a7b3
docs(idempotency): cleanup redis usage and link with setup/infra
heitorlessa 92307cb
docs(idempotency): cleanup idempotent decorator; inline admonitions
heitorlessa 06dc1ee
docs(idempotency): cleanup idempotent_decorator section
heitorlessa eb42534
docs(idempotency): cleanup serialization, fields subset, move batch t…
heitorlessa 2344e01
docs: cleanup handling exceptions
heitorlessa 6632396
docs: move caching to getting started
heitorlessa 51a7af7
docs: use env var for DDB table, no hardcode
heitorlessa 5807a1f
docs: moved expiration window to getting started; updated example to …
heitorlessa 9f90c39
docs: include IdempotencyValidationError in example
heitorlessa 66549a6
Fixing errors on Redis examples
leandrodamascena 0a46164
docs(config): add social links
heitorlessa dbbd6f5
docs(idempotency): cleanup intro and key features
heitorlessa 6d58fae
docs(idempotency): cleanup getting started ddb vs redis
heitorlessa 11bc9fb
docs(idempotency): break iam permissions into table; IAM permission t…
heitorlessa e65e8bd
docs(idempotency): cleanup dynamodb required resource; break subsecti…
heitorlessa fa2b067
docs(idempotency): make terminologies crispier
heitorlessa 108f456
docs(idempotency): line editing before decorators
heitorlessa dd90766
docs(idempotency): cleanup timeout section
heitorlessa cf39547
docs(idempotency): use cards for required resources
heitorlessa 6776d79
docs(idempotency): note to skip timeout section when using handler de…
heitorlessa 55a9fc6
docs: remove tabbed content for single timeout snippet
heitorlessa d900b12
docs: cleanup persistence layers attrs, snippet titles etc
heitorlessa 6c02031
docs: typo in batch integration
heitorlessa 14d4f4d
docs: rename batch integration to actual use case name
heitorlessa bb23ce9
docs(idempotency): cleanup default behavior section
heitorlessa f795c2e
docs: move bold to draw attention to whole event as idempotency key
heitorlessa aa25c42
docs: lead with parameter name over config name
heitorlessa 8837b1d
docs: moved composite key under DDB section
heitorlessa 0145c8d
docs: cut unnecessary anchor name
heitorlessa ea1792e
docs: fix broken links after sections renaming
heitorlessa 97211e6
Making mypy happy
leandrodamascena 9dc9e94
docs: fix conflicts out of order
heitorlessa aeece16
docs(leandro's feedback): add caching in key features
heitorlessa 8d3fee2
Apply suggestions from code review
heitorlessa 3c4e56b
docs(leandro's feedback): time window placement
heitorlessa fc02e17
docs(leandro's feedback): key features success vs failure ambiguity
heitorlessa ea159c9
docs(leandro's feedback): Redis anchor name
heitorlessa b1ad23e
docs(leandro's feedback): remove ambiguity on Redis VPC connectivity
heitorlessa f052d2c
Update docs/utilities/idempotency.md
heitorlessa 738f2fc
Update docs/utilities/idempotency.md
heitorlessa f8318f4
docs: move primary key for both persistence storages plus additional ctx
heitorlessa 30e1e89
Merge branch 'develop' into docs/idempotency-guarantees
leandrodamascena File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,38 @@ | ||
import os | ||
|
||
import requests | ||
|
||
from aws_lambda_powertools.utilities.idempotency import ( | ||
DynamoDBPersistenceLayer, | ||
IdempotencyConfig, | ||
idempotent_function, | ||
) | ||
from aws_lambda_powertools.utilities.idempotency.exceptions import IdempotencyPersistenceLayerError | ||
from aws_lambda_powertools.utilities.typing import LambdaContext | ||
|
||
persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable") | ||
table = os.getenv("IDEMPOTENCY_TABLE", "") | ||
persistence_layer = DynamoDBPersistenceLayer(table_name=table) | ||
|
||
config = IdempotencyConfig() | ||
|
||
|
||
def lambda_handler(event: dict, context: LambdaContext): | ||
# If an exception is raised here, no idempotent record will ever get created as the | ||
# idempotent function does not get called | ||
try: | ||
endpoint = "https://jsonplaceholder.typicode.com/comments/" # change this endpoint to force an exception | ||
requests.get(endpoint) | ||
except Exception as exc: | ||
return str(exc) | ||
|
||
call_external_service(data={"user": "user1", "id": 5}) | ||
|
||
# This exception will not cause the idempotent record to be deleted, since it | ||
# happens after the decorated function has been successfully called | ||
raise Exception | ||
|
||
|
||
@idempotent_function(data_keyword_argument="data", config=config, persistence_store=persistence_layer) | ||
def call_external_service(data: dict): | ||
# Any exception raised will lead to idempotency record to be deleted | ||
result: requests.Response = requests.post( | ||
"https://jsonplaceholder.typicode.com/comments/", | ||
json={"user": data["user"], "transaction_id": data["id"]}, | ||
json=data, | ||
) | ||
return result.json() | ||
|
||
|
||
def lambda_handler(event: dict, context: LambdaContext): | ||
try: | ||
call_external_service(data=event) | ||
except IdempotencyPersistenceLayerError as e: | ||
# No idempotency, but you can decide to error differently. | ||
raise RuntimeError(f"Oops, can't talk to persistence layer. Permissions? error: {e}") | ||
|
||
# This exception will not impact the idempotency of 'call_external_service' | ||
# because it happens in isolation, or outside their scope. | ||
raise SyntaxError("Oops, this shouldn't be here.") |
5 changes: 4 additions & 1 deletion
5
examples/idempotency/src/working_with_idempotency_key_required.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.