[HELP/ADVICE] Best ways/examples of testing lambda functions

Are there any good example blogs/articles that can demonstrate how to test lambda functions efficiently? Are there any frameworks (node based) that are you there to help with this?

Would like to be able to see how people have mocked responses from AWS services and unit tested any isolated bits of code. All the articles I’m pulling up seem to just console long in place, which is deffo not what I want to do.


Related discussions:

I find this localstack is a good tool for local dev https://github.com/localstack/localstack

We’ve tested some lambda functions by using a sample json input file, containing the same information that the lambda function would normally be called with, then you can either call the function in lambda with this data & use regular unit testing packages to assert that the correct output was generated, or you can call the function locally from a node environment.

It gets trickier if the lambda function needs to call information from AWS, for this we have a development AWS account that we can deploy the function into & create appropriate resources.

If you’ve got control over function inputs like this, you should be able to use nodejs unit testing packages. Our lambda code is primarily in Python, so I can’t comment on exact code & packages to use but you should be able to use the same approach.

Hey - I’d look into the Serverless framework

Hi there, we struggled with this as well and just updated and released the Stackery CLI to develop and debug any AWS Lambda against any AWS service for any language. https://www.stackery.io/blog/local-debugging-any-aws-lambda-function/

In general mocking AWS services is a fail, so if you can use the live services, you remove a broad set of permissions and parameter errors from your debugging efforts. At the same time, your Lambdas connect to other services, so you have to be able to invoke across those services as well. The AWS SAM CLI is part of our tooling, so if you’ve used that you know how well it keeps up with the Lambda runtimes, but not other services or runtime layers.

We’re pretty excited about offering this to everyone, so please let us know how you fare with it.