Skip to content

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

Closed

Description

@Dunedan

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.

Activity

  1. added
    feature-request
    triage
    on Mar 8, 2021
  2. removed
    triage
    on Mar 8, 2021
  3. heitorlessa commented on Mar 8, 2021

    @heitorlessa
    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?

  4. Dunedan commented on Mar 8, 2021

    @Dunedan
    ContributorAuthor

    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.

  5. heitorlessa commented on Mar 9, 2021

    @heitorlessa
    Contributor

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

  6. added this to the 1.12.0 milestone on Mar 9, 2021
  7. michaelbrewer commented on Mar 11, 2021

    @michaelbrewer
    Contributor

    @heitorlessa @Dunedan I drafted a PR for this.

  8. added
    pending-release
    on Mar 12, 2021
  9. heitorlessa commented on Mar 12, 2021

    @heitorlessa
    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

  10. Dunedan commented on Mar 12, 2021

    @Dunedan
    ContributorAuthor

    Awesome. Thanks a lot. 👍

  11. michaelbrewer commented on Mar 12, 2021

    @michaelbrewer
    Contributor

    Awesome. Thanks a lot. 👍

    thanks for bringing it up, it was a good catch

  12. removed this from the 1.12.0 milestone on Mar 17, 2021
  13. heitorlessa commented on Mar 17, 2021

    @heitorlessa
    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!

  14. removed
    pending-release
    on Mar 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-request

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions