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

Feature request: idempotent decorator for Lambda handler #1306

Closed
1 of 2 tasks
saragerion opened this issue Feb 17, 2023 · 4 comments
Closed
1 of 2 tasks

Feature request: idempotent decorator for Lambda handler #1306

saragerion opened this issue Feb 17, 2023 · 4 comments
Labels
feature-request This item refers to a feature request for an existing or new utility idempotency This item relates to the Idempotency Utility rejected This is something we will not be working on. At least, not in the measurable future

Comments

@saragerion
Copy link
Contributor

saragerion commented Feb 17, 2023

Use Case

Users who write their Lambda functions as classes should be able to make their function handler idempotent via decorator.

Solution/User Experience

import { LambdaInterface } from '@aws-lambda-powertools/commons';
import { 
  idempotentHandler,
  DynamoDBPersistenceLayer,
  IdempotencyConfig,
} from '@aws-lambda-powertools/idempotency';

const config = new IdempotencyConfig({...});
const ddbPersistenceLayer = new DynamoDBPersistenceLayer({...});

class Lambda implements LambdaInterface {
  // Decorate your handler class method
  @idempotentHandler({
    persistenceStore: ddbPersistenceLayer,
    config
  })
  public async handler(_event: unknown, _context: unknown): Promise<void> {
    /* ...Function logic here... */
  }
}

export const handlerClass = new Lambda();
export const handler = handlerClass.handler.bind(handlerClass);

The idempotentHandler decorator should be able to decorate an handler method of a LambdaInterface class, both async and sync. The decorator should accept an object with mandatory persistenceStore and an optional config one. The former should be an instance of any class that extends BasePersistenceLayer, while the latter should be an instance of the class IdempotencyConfig.

Following the Powertools for Python implementation, the decorator should:

  • return early if the POWERTOOLS_IDEMPOTENCY_DISABLED env variable has a truthy value (using EnvironmentVariableService)
  • use the provided config object or instantiate a new one if none is passed
  • register the Lambda context into the config object (used to manage timeouts)
  • instantiate an IdempotencyHandler
  • call & return the IdempotencyHandler.handle() method

This last step will ensure that the IdempotencyHandler will perform all the actions needed to make the function idempotent.

Alternative solutions

No response

Acknowledgment

@saragerion saragerion added triage This item has not been triaged by a maintainer, please wait feature-request This item refers to a feature request for an existing or new utility labels Feb 17, 2023
@saragerion saragerion added this to the Idempotency - Beta release milestone Feb 17, 2023
@saragerion saragerion added the idempotency This item relates to the Idempotency Utility label Feb 17, 2023
@dreamorosi dreamorosi added the discussing The issue needs to be discussed, elaborated, or refined label Feb 17, 2023
@dreamorosi dreamorosi changed the title Feature request (idempotency): make Lambda handler idempotent via decorator for events in sequence (happy path) Feature request: make Lambda handler idempotent via decorator for events in sequence (happy path) Feb 17, 2023
@dreamorosi dreamorosi removed the triage This item has not been triaged by a maintainer, please wait label Feb 17, 2023
@dreamorosi dreamorosi changed the title Feature request: make Lambda handler idempotent via decorator for events in sequence (happy path) Feature request: idempotent decorator for Lambda handler Mar 20, 2023
@dreamorosi dreamorosi added confirmed The scope is clear, ready for implementation blocked This item's progress is blocked by external dependency or reason and removed discussing The issue needs to be discussed, elaborated, or refined confirmed The scope is clear, ready for implementation labels Mar 20, 2023
@dreamorosi dreamorosi added completed This item is complete and has been merged/shipped and removed blocked This item's progress is blocked by external dependency or reason labels Apr 24, 2023
@dreamorosi dreamorosi added confirmed The scope is clear, ready for implementation and removed completed This item is complete and has been merged/shipped labels Apr 24, 2023
@dreamorosi dreamorosi added on-hold This item is on-hold and will be revisited in the future and removed confirmed The scope is clear, ready for implementation labels Jun 22, 2023
@dreamorosi
Copy link
Contributor

We have decided to hold back the decorator and not include it in the beta release.

Read more about why in #1375.

@dreamorosi dreamorosi added rejected This is something we will not be working on. At least, not in the measurable future and removed on-hold This item is on-hold and will be revisited in the future labels Jul 31, 2023
@dreamorosi dreamorosi removed this from the Version 2.0 milestone Jul 31, 2023
@dreamorosi
Copy link
Contributor

dreamorosi commented Jul 31, 2023

Given that Powertools for AWS (Python) is deprecating decorator usage we have decided to not implement this feature in this version.

EDIT: In the previous edit of this message I mistakenly referred to the deprecation of the Batch Processing decorator in Powertools for AWS (Python), now marked as "legacy", and mixed it with the Idempotency utility which has no plans of deprecating decorator-based usage. I regret the mistake and apologize for the confusion it might have caused.


At the moment we are not planning on implementing the decorator for Idempotency in Powertools for AWS (TypeScript) but we are are open to reconsider this decision in the future if there's enough customer demand.

For now we will remove it from the backlog.

@github-actions
Copy link
Contributor

⚠️ COMMENT VISIBILITY WARNING ⚠️

Comments on closed issues 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.

@dreamorosi dreamorosi closed this as not planned Won't fix, can't repro, duplicate, stale Jul 31, 2023
@github-actions
Copy link
Contributor

⚠️ COMMENT VISIBILITY WARNING ⚠️

Comments on closed issues 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request This item refers to a feature request for an existing or new utility idempotency This item relates to the Idempotency Utility rejected This is something we will not be working on. At least, not in the measurable future
Projects
Development

No branches or pull requests

3 participants