Skip to content

Conversation

heitorlessa
Copy link
Contributor

@heitorlessa heitorlessa commented Aug 20, 2021

Issue #, if available: aws-powertools/powertools-lambda#32

Description of changes:

  • Remove dependency on context
  • Use data instead of event for params
  • Make IdempotencyHandler generic for any function
  • Update docstring that refers to Lambda event only
  • New decorator that takes a data_argument
  • Update docs with new UX for any function
  • Preserve decorated function argument types w/ generic callable

UX

from aws_lambda_powertools.utilities.batch import sqs_batch_processor
from aws_lambda_powertools.utilities.idempotency import idempotent_function, DynamoDBPersistenceLayer, IdempotencyConfig


dynamodb = DynamoDBPersistenceLayer(table_name="idem")
config =  IdempotencyConfig(
    event_key_jmespath="messageId",
    use_local_cache=True,
)


@idempotent_function(data_keyword_argument="record", persistence_layer=dynamodb, config=config)
def record_handler(record):
    return do_something_with(record["body"])


@sqs_batch_processor(record_handler=record_handler)
def lambda_handler(event, context):
    return {"statusCode": 200}

Checklist

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 20, 2021
@heitorlessa heitorlessa added this to the 1.20.0 milestone Aug 20, 2021
@pull-request-size pull-request-size bot removed the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 20, 2021
@pull-request-size pull-request-size bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Aug 20, 2021
@codecov-commenter
Copy link

codecov-commenter commented Aug 20, 2021

Codecov Report

Merging #625 (5f27b2b) into develop (3fa6803) will increase coverage by 0.02%.
The diff coverage is 99.11%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #625      +/-   ##
===========================================
+ Coverage    99.95%   99.97%   +0.02%     
===========================================
  Files          114      116       +2     
  Lines         4594     4846     +252     
  Branches       253      265      +12     
===========================================
+ Hits          4592     4845     +253     
+ Partials         2        1       -1     
Impacted Files Coverage Δ
...wertools/utilities/idempotency/persistence/base.py 99.36% <96.55%> (+<0.01%) ⬆️
aws_lambda_powertools/shared/constants.py 100.00% <100.00%> (ø)
aws_lambda_powertools/shared/types.py 100.00% <100.00%> (ø)
aws_lambda_powertools/tracing/tracer.py 100.00% <100.00%> (ø)
...ambda_powertools/utilities/idempotency/__init__.py 100.00% <100.00%> (ø)
...ws_lambda_powertools/utilities/idempotency/base.py 100.00% <100.00%> (ø)
...da_powertools/utilities/idempotency/idempotency.py 100.00% <100.00%> (+1.47%) ⬆️
...lambda_powertools/utilities/data_classes/common.py 100.00% <0.00%> (ø)
...ols/utilities/data_classes/kinesis_stream_event.py 100.00% <0.00%> (ø)
.../utilities/data_classes/api_gateway_proxy_event.py 100.00% <0.00%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3fa6803...5f27b2b. Read the comment docs.

@heitorlessa heitorlessa marked this pull request as ready for review August 20, 2021 13:57
@heitorlessa
Copy link
Contributor Author

@michaelbrewer @cakepietoast could either of you have a look just in case? tks!

Copy link
Contributor

@michaelbrewer michaelbrewer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good.

@boring-cyborg boring-cyborg bot added the dependencies Pull requests that update a dependency file label Aug 21, 2021
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Aug 21, 2021
@heitorlessa heitorlessa merged commit 260fa86 into aws-powertools:develop Aug 21, 2021
@heitorlessa heitorlessa deleted the feat/idempotency-method branch August 21, 2021 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants