powertools-lambda-typescript
powertools-lambda-typescript copied to clipboard
Feature request: add support for Durable functions in Decorators
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
- Create a lambda function with a durable config specified, and the handler above
- Invoke the function
- 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