Skip to content

Feature request: idempotent decorator for function methods #1304

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

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

Feature request: idempotent decorator for function methods #1304

saragerion opened this issue Feb 17, 2023 · 3 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 any calls method idempotent via decorator.

Solution/User Experience

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

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

class Lambda implements LambdaInterface {
  // Decorate your handler class method
  @idempotentMethod({
    persistenceStore: ddbPersistenceLayer,
    dataArgument: 'message',
    config
  })
  private myMethod(message: Record<string, unknown>, time: number): void {
    /* ...Function logic here... */
  }

  public async handler(_event: unknown, _context: unknown): Promise<void> {
    this.myMethod({ foo: 'bar' }, Date.now());
  }
}

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

The idempotentMethod decorator should be able to decorate any class method of a LambdaInterface class, both async and sync. The decorator should accept an object with mandatory persistenceStore and dataArgument fields, as well as an optional config one. The former should be an instance of any class that extends BasePersistenceLayer, the second should be a string that represents the argument to be used for idempotency (in the decorated method), 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 changed the title Feature request (idempotency): handling scenario of concurrent executions Feature request: handling scenario of concurrent executions Feb 17, 2023
@dreamorosi dreamorosi added discussing The issue needs to be discussed, elaborated, or refined and removed triage This item has not been triaged by a maintainer, please wait labels Feb 17, 2023
@dreamorosi dreamorosi changed the title Feature request: handling scenario of concurrent executions Feature request: idempotent decorator for function methods 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 moved this from Backlog to On hold in Powertools for AWS Lambda (TypeScript) Jun 22, 2023
@dreamorosi dreamorosi added on-hold This item is on-hold and will be revisited in the future and removed blocked This item's progress is blocked by external dependency or reason 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
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.

@dreamorosi dreamorosi closed this as not planned Won't fix, can't repro, duplicate, stale Jul 31, 2023
@github-project-automation github-project-automation bot moved this from On hold to Coming soon in Powertools for AWS Lambda (TypeScript) Jul 31, 2023
@dreamorosi dreamorosi removed this from the Version 2.0 milestone Jul 31, 2023
@dreamorosi dreamorosi moved this from Coming soon to Closed in Powertools for AWS Lambda (TypeScript) Jul 31, 2023
@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
@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

2 participants