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: asLambda implementation prevents access to Lambda context, and prevents use of middleware #917

Open
dmeehan1968 opened this issue Oct 26, 2023 · 0 comments

Comments

@dmeehan1968
Copy link

Here is a typical example of using Powertools Logger, then adding the Lambda context so that its added to the structure log entries sent to CloudWatch:

import { Logger } from '@aws-lambda-powertools/logger';

const logger = new Logger({ serviceName: 'serverlessAirline' });

export const handler = async (_event, context): Promise<void> => {
  logger.addContext(context)
};

The existing asLambda implementation specifically expects the provided function have only one argument (the input) so that the signature can be used both for the exported handler (for the benefit of NodeJsFunction) and also as a call from within a state machine. If a second argument is added, it causes state machine calls to show a type error (missing argument), and when passed through the ts2asl compiler and error is thrown:

// logger setup as above
export const myLambda = asl.deploy.asLambda(async (input: any, context: Context) => {
    logger.addContext(context)
})

The error:

Error: Lambda declaration must be callable with 0 or 1 argument

With Lambda Powertools, clients for logging, metrics etc can be added by using middy middleware, which wraps the handler declaration. I've not tried it, but it looks like it would be incompatible with how ts2asl currently identifies lambda declarations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant