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

Feature request: add support for Durable functions in Decorators

Open ConnorKirk opened this issue 3 weeks ago • 0 comments

Expected Behavior

I am able to use Powertools class decorators with Durable Function handlers

Current Behavior

Typescript emits a warning, as the Handler interface does not accept the DurableContext type.

The decorators break, as they try to access properties on the Lambda Context, but these must be accessed with a different path in the DurableContext type.

Code snippet

import {
  withDurableExecution,
  type DurableContext,
} from "@aws/durable-execution-sdk-js";
import { Logger, LogLevel } from "@aws-lambda-powertools/logger";

import { LambdaInterface } from "@aws-lambda-powertools/commons/types";

const logger = new Logger({
  serviceName: "test-suite-validation",
  logLevel: LogLevel.TRACE,
});

class Lambda implements LambdaInterface {
  // Decorate your handler class method
  @logger.injectLambdaContext()
  public async handler(
    _event: unknown,
    _context: DurableContext
  ): Promise<void> {
    logger.info("This is an INFO log with some context");
  }
}

const myFunction = new Lambda();
export const handler = withDurableExecution(
  myFunction.handler.bind(myFunction)
);

Steps to Reproduce

  1. Create a lambda function with a durable config specified, and the handler above
  2. Invoke the function
  3. Observe an error is raised

Possible Solution

Update the Handler type in aws-lambda to accept a LambdaContext or a Durable Context

or

Create a new DurableHandler type?

Update decorators to correctly access the Lambda Context when passed a Durable Context

Powertools for AWS Lambda (TypeScript) version

latest

AWS Lambda function runtime

24.x

Packaging format used

npm

Execution logs


ConnorKirk avatar Dec 02 '25 17:12 ConnorKirk