-
Notifications
You must be signed in to change notification settings - Fork 20
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
Best way to test handlers without actually deploying #66
Comments
I think the SAM CLI has support for running lambda functions locally and is also integrated with the CDK: https://sanderknape.com/2019/05/building-serverless-applications-aws-cdk/. Perhaps we could try that? Do you want your function to run against live AWS resources or locally mocked? I test handlers with unit tests by passing in mocked clients for the dependencies: const table = new DynamoDB.Table(..)
const f = new Lambda.Function(.., { depends: table.readAccess() })
const mockTableClient = ...
const result = await f.handler(event, mockTableClient); |
the SAM CLI looks a good starting point! I'll take a look, as I was thinking more of calling the handler from the command line or even from an adjacent file that can do the wiring on the 'synthesized' bundle. my goal was to help debugging the issues with the generated code, but might come in handy when debugging own code as well. |
The generated code should (hopefully) be entirely transparent to the user once its mature. Is it still causing problems? The |
Apologies that the |
no worries! we are in for the ride, it's expectedly highly iterative 👍 the issue was mainly because of that internal webpack error (#57), it wasn't a problem with the handler per-se, nor with the external code (that is testable in isolation). the handler should be slim anyway (ApiGateway.response with your response shape) and no, it's deploying as expected, just hit the missing CORS headers nag (the APIGW one) unrelated to this. |
Might be out of the scope of punchcard to provide a cli or a helper library (like @punchcard/test semi serious 😃), but it's related to #63, I'm trying to run node debugger, but there are too many spawning processes that make breakpoints useless (node that calls cdk synth that calls ts-node). this is really useful and is akin to serverless-offline.
Another issue with debugging the generated code while on lambda is that there's only X-Ray, and you can't actually get insight of that happening inside scopes and the current call stack, having to change code to spit out
console.log
statements are icky.The text was updated successfully, but these errors were encountered: