how would one run aws lambda locally (java) for testing

SAM Local - http://docs.aws.amazon.com/lambda/latest/dg/test-sam-local.html and docker-lambda - https://github.com/lambci/docker-lambda have worked well for APIs that need only javaee and project sources. I am still trying to figure out how to set to set the classpath to include the gradle dependencies.


AFAIK there is no magic to actually triggering the lambda function locally. Take a look at: http://docs.aws.amazon.com/lambda/latest/dg/java-programming-model-req-resp.html
and
http://docs.aws.amazon.com/lambda/latest/dg/java-gs.html

Depending what your lambda code does you need to build the input and (possibly the context) and pass them into the function writing your own small test wrapper.

Unless you are doing this for unit testing it does not make sense to go through the trouble though. If you are doing this for testing you will probably need to mock out other external AWS services that your lambda might use.


You can use AWS Toolkit for Eclipse if you want to perform local testing for Amazon Lambda functions, and build serverless applications in Amazon.

But since Aug 11, 2017, Amazon provides the AWS SAM Local, a CLI tool that allows us to locally test and debug our AWS Lambda functions. SAM Local supports Lambda functions written in Node.js, Java, and Python.

Please vote for implementing Intellij IDEA support for Amazon Lambda here:

  • https://youtrack.jetbrains.com/issue/IDEA-180070

There are a number of projects going on to run the entire AWS stack locally.

Java I believe the main option is Localstack

If you're on Javascript you can go Serverless