powertools-lambda-python icon indicating copy to clipboard operation
powertools-lambda-python copied to clipboard

Feature request: Simplify experience in discovering how much time left before Idempotency record expiration

Open heitorlessa opened this issue 1 year ago • 1 comments

Use case

Provide a method to return a datetime object to make it easier to manipulate for customers building APIs, webhooks, and observable systems.

Docs

As of now, this is what we are expecting customers to do which is error prone for the non-initiated.

...

    # expiry_timestamp could be None so include if set
    expiry_timestamp = idempotent_data.expiry_timestamp
    if expiry_timestamp:
        expiry_time = datetime.datetime.fromtimestamp(int(expiry_timestamp))
        response["x-idempotent-expiration"] = expiry_time.isoformat()

    # Must return the response here
    return response

Solution/User Experience

    # this solution is not correct for edge cases, mostly for illustration
    def get_expiration_datetime(self) -> datetime | None:
        if self.expiry_timestamp:
            return datetime.datetime.fromtimestamp(int(self.expiry_timestamp))
        return None

Alternative solutions

Customers use the `expiry_timestamp` which they need to convert and manipulate from scratch.

https://docs.powertools.aws.dev/lambda/python/latest/utilities/idempotency/#manipulating-the-idempotent-response

Acknowledgment

heitorlessa avatar Jul 25 '24 08:07 heitorlessa

cc @dreamorosi @hjgraca @jeromevdl so it's on everyone's radar for a good UX and think a name+logic that works for everyone

heitorlessa avatar Jul 25 '24 08:07 heitorlessa

Closed as complete.

leandrodamascena avatar Aug 27 '24 10:08 leandrodamascena

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Aug 27 '24 10:08 github-actions[bot]

This is now released under 3.0.0 version!

github-actions[bot] avatar Sep 23 '24 10:09 github-actions[bot]