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

Bug: idempotencyHandler not using registered context when saving in progress #1482

Closed
dreamorosi opened this issue Jun 2, 2023 · 2 comments · Fixed by #1540
Closed

Bug: idempotencyHandler not using registered context when saving in progress #1482

dreamorosi opened this issue Jun 2, 2023 · 2 comments · Fixed by #1540
Assignees
Labels
bug Something isn't working completed This item is complete and has been merged/shipped idempotency This item relates to the Idempotency Utility

Comments

@dreamorosi
Copy link
Contributor

Expected Behaviour

When using the idempotentLambdaHandler, idempotentFunction decorators, or makeFunctionIdempotent function wrapper the underlying idempotency handler should use the Lambda context to determine the remaining milliseconds in the current execution when saving a record as in-progress. This way, if an execution times out while processing it can be handled correctly later on.

Current Behaviour

The context is never used in the IdempotencyHandler module and the idempotentLambdaHandler never calls idempotencyConfig.registerLambdaContext(context) - those are two separate but related issues.

As a result, even though the operation is made idempotent, the handler logs this warning:

2023-06-02T16:42:39.239Z 7bac60e0-3084-403c-9c69-be9f20d0e761 WARN Could not determine remaining time left. Did you call registerLambdaContext on IdempotencyConfig?

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,
  })
  public async handler(event: EventRecord, _context: Context): Promise<string> {
    logger.info("Got test event:", { event });
    return "Processing done: " + event.foo;
  }
}

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

Steps to Reproduce

  1. Deploy the code
  2. Run it
  3. Observe the warning in the logs & the absence of the in_progress_expiry_attr value in the DynamoDB Table

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 dreamorosi added this to the Idempotency - Beta release milestone Jun 2, 2023
@am29d am29d assigned am29d and unassigned am29d Jun 20, 2023
@am29d am29d moved this from Working on it to Backlog in Powertools for AWS Lambda (TypeScript) Jun 21, 2023
@am29d am29d moved this from Backlog to Working on it in Powertools for AWS Lambda (TypeScript) Jun 21, 2023
@am29d am29d self-assigned this Jun 21, 2023
@github-project-automation github-project-automation bot moved this from Working on it to Coming soon in Powertools for AWS Lambda (TypeScript) Jun 22, 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.

@github-actions github-actions bot added pending-release This item has been merged and will be released soon and removed confirmed The scope is clear, ready for implementation labels Jun 22, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jun 23, 2023

This is now released under version 1.10.0!

@github-actions github-actions bot added completed This item is complete and has been merged/shipped and removed pending-release This item has been merged and will be released soon labels Jun 23, 2023
@dreamorosi dreamorosi moved this from Coming soon to Shipped in Powertools for AWS Lambda (TypeScript) Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working completed This item is complete and has been merged/shipped idempotency This item relates to the Idempotency Utility
Projects
Development

Successfully merging a pull request may close this issue.

2 participants