Skip to content

Bug: idempotentLambdaHandler breaks when used with other decorators #1481

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
dreamorosi opened this issue Jun 2, 2023 · 4 comments
Closed
Labels
bug Something isn't working 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

@dreamorosi
Copy link
Contributor

Expected Behaviour

As a customer I should be able to use multiple class method decorators in conjunction with Idempotency's idempotentLambdaHandler decorator. The decorator should do its job and either allow other decorators to run or bail cleanly.

Current Behaviour

When using multiple decorators (i.e. idempotentLambdaHandler & logger.injectLambdaContext) with idempotentLambdaHandler being the first one, the function throws an error like this:

{"errorType":"TypeError","errorMessage":"Cannot read properties of undefined (reading 'invokedFunctionArn')","trace":["TypeError: Cannot read properties of undefined (reading 'invokedFunctionArn')"," at Logger.addContext (/var/task/index.js:3584:35)"," at Logger.injectLambdaContextBefore (/var/task/index.js:3662:13)"," at descriptor.value [as functionToMakeIdempotent] (/var/task/index.js:3643:16)"," at IdempotencyHandler.getFunctionResult (/var/task/index.js:1203:31)"," at IdempotencyHandler.processIdempotency (/var/task/index.js:1243:21)"," at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"," at async IdempotencyHandler.handle (/var/task/index.js:1223:20)"]}

Code snippet

import type { Context } from "aws-lambda";
import type { LambdaInterface } from "@aws-lambda-powertools/commons";
import { Logger } from "@aws-lambda-powertools/logger";
import { idempotentLambdaHandler } from "@aws-lambda-powertools/idempotency";
import { DynamoDBPersistenceLayer } from "@aws-lambda-powertools/idempotency/dynamodb";
import { IdempotencyConfig } from "@aws-lambda-powertools/idempotency";

type EventRecord = {
  foo: string;
};

const logger = new Logger();

const dynamoDBPersistenceLayer = new DynamoDBPersistenceLayer({
  tableName:
    process.env.IDEMPOTENCY_TABLE_NAME || "lambda-powertools-playground-table",
});
const idempotencyConfig = new IdempotencyConfig({});

class Lambda implements LambdaInterface {
  @idempotentLambdaHandler({
    persistenceStore: dynamoDBPersistenceLayer,
  })
  @logger.injectLambdaContext({ logEvent: true })
  public async handler(event: EventRecord, _context: Context): Promise<string> {
    return "Processing done: " + event.foo;
  }
}

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

Steps to Reproduce

  1. Deploy the function above
  2. Run it
  3. Observe the error

Possible Solution

No response

Powertools for AWS Lambda (TypeScript) version

latest

AWS Lambda function runtime

18.x

Packaging format used

npm

Execution logs

No response

@dreamorosi dreamorosi added bug Something isn't working idempotency This item relates to the Idempotency Utility confirmed The scope is clear, ready for implementation labels Jun 2, 2023
@dreamorosi
Copy link
Contributor Author

Need to look into it further, but the stack trace shows that the Logger decorator is not able to read info from the Lambda context object. This suggests that the idempotentLambdaHandler decorator is somehow mutating the decorated method preventing subsequent decorators to read the context.

Swapping the order of decorators (i.e. idempotentLambdaHandler last) works normally.

@dreamorosi dreamorosi added this to the Idempotency - Beta release milestone Jun 2, 2023
@dreamorosi dreamorosi moved this from Backlog to On hold in Powertools for AWS Lambda (TypeScript) Jun 22, 2023
@dreamorosi dreamorosi added blocked This item's progress is blocked by external dependency or reason and removed confirmed The scope is clear, ready for implementation labels Jun 22, 2023
@dreamorosi
Copy link
Contributor Author

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 Author

Since we have closed #1304 and #1306 and decided to not implement decorators for this utility, we are closing this issue for the time being.

@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 added rejected This is something we will not be working on. At least, not in the measurable future and removed blocked This item's progress is blocked by external dependency or reason labels Jul 31, 2023
@dreamorosi dreamorosi moved this from Coming soon to Closed in Powertools for AWS Lambda (TypeScript) Jul 31, 2023
@dreamorosi dreamorosi removed this from the Version 2.0 milestone 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
bug Something isn't working 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

1 participant