Skip to content
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

Idempotency: Single DynamoDB table for multiple AWS Lambda functions #318

Closed
Dunedan opened this issue Mar 8, 2021 · 8 comments
Closed
Labels
feature-request feature request

Comments

@Dunedan
Copy link
Contributor

Dunedan commented Mar 8, 2021

First of all, thanks for another great release. 👍

I got a feature request for the new idempotency feature: As I understand the documentation, the key_attr of the DynamoDB table consists solely of the hashed idempotency key, which is based on the payload. That makes it hard to use a single DynamoDB table for multiple different AWS Lambda functions which expect the same payloads. I guess it'd be possible to somehow ensure that there is some kind of static identifier in event_key_jmespath, but that feels cumbersome and error prone.

It'd be great to have the ability to have something like the function name included in the key_attr so it's possible for multiple AWS Lambda functions to share the same DynamoDB table to avoid having to create a new table for each AWS Lambda function.

@Dunedan Dunedan added feature-request feature request triage Pending triage from maintainers labels Mar 8, 2021
@heitorlessa heitorlessa removed the triage Pending triage from maintainers label Mar 8, 2021
@heitorlessa
Copy link
Contributor

Hey @Dunedan - Thanks for raising this feature request, and it's also awesome to hear about the new release.

Could you share an example where different Lambda functions would handle the same payload and idempotence key?

I can see that when you're using an orchestration layer like Step Functions, where the same state could be sent to multiple functions. For example, a booking process where the idempotency key, event_key_jmespath, would be order_id and customer_id the same for multiple functions - Problem here is that the return differs because one might be used for reserve booking, other for reserve payment, and while you could have a slight different idempotence key it could be error prone.

Does that capture the challenge you had in mind?

@Dunedan
Copy link
Contributor Author

Dunedan commented Mar 8, 2021

Could you share an example where different Lambda functions would handle the same payload and idempotence key?

The example I had in mind have been multiple AWS Lambda functions triggered by the same SNS topic. However I now believe the payload would be slightly different in this case for each AWS Lambda function, as at least the EventSubscriptionArn key should have a different value per invoked AWS Lambda function.

I can see that when you're using an orchestration layer like Step Functions, where the same state could be sent to multiple functions. For example, a booking process where the idempotency key, event_key_jmespath, would be order_id and customer_id the same for multiple functions - Problem here is that the return differs because one might be used for reserve booking, other for reserve payment, and while you could have a slight different idempotence key it could be error prone.

Does that capture the challenge you had in mind?

Yes, that'd be a similar situation to the one I had in mind with SNS.

I believe in practice the chance to have multiple AWS Lambda functions with the same payload and idempotence key is very low, but nevertheless as far as I can see, there is nothing in the code to prevent unexpected behavior in case it does happen. That makes me a bit uncomfortable using the same DynamoDB table for multiple functions, as I have to remember to explicitly check each AWS Lambda function for possible collisions of the payload and idempotence key.

@heitorlessa
Copy link
Contributor

Perfect, that makes sense - We'll ping you back here once we have an initial implementation to review :)

@heitorlessa heitorlessa added this to the 1.12.0 milestone Mar 9, 2021
@michaelbrewer
Copy link
Contributor

@heitorlessa @Dunedan I drafted a PR for this.

@heitorlessa heitorlessa added the pending-release Fix or implementation already in dev waiting to be released label Mar 12, 2021
@heitorlessa
Copy link
Contributor

it's now merged @Dunedan - Set a release date for 1.12 with this and other minor enhancements like correlation_id to be launched next Wed

@Dunedan
Copy link
Contributor Author

Dunedan commented Mar 12, 2021

Awesome. Thanks a lot. 👍

@michaelbrewer
Copy link
Contributor

Awesome. Thanks a lot. 👍

thanks for bringing it up, it was a good catch

@heitorlessa heitorlessa removed this from the 1.12.0 milestone Mar 17, 2021
@heitorlessa
Copy link
Contributor

Hey @Dunedan this is now available in 1.12.0 ;) Give it a try, and let us know if there's anything else you need before we prepare to go GA in one or two releases: https://github.com/awslabs/aws-lambda-powertools-python/releases/tag/v1.12.0

Thanks again for the idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request feature request
Projects
Development

No branches or pull requests

3 participants