Skip to content

Feature request: add support for Durable functions in Decorators #4832

@ConnorKirk

Description

@ConnorKirk

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

Metadata

Metadata

Assignees

Labels

confirmedThe scope is clear, ready for implementationfeature-requestThis item refers to a feature request for an existing or new utility

Type

No type

Projects

Status

Working on it

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions