Description
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
- Deploy the function above
- Run it
- 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
Metadata
Metadata
Assignees
Labels
Type
Projects
Status