Testing a Hello-World AWS Lambda Function Locally with Docker

Testing a hello_world AWS Lambda Function Locally with Docker#

At this point, before we've even made any code updates - we have a fully functioning and deployable lambda. Sure it just says "Hello World" - but it's a start. We'll go ahead and invoke it locally just to confirm our environment is configured correctly.

From our dicebot directory, we will use the command sam build -u build a SAM package with docker. The -u flag is necessary to ensure docker is used to build the package. Using -u is not strictly required, but we recommended always using it so that we are sure our package is being built against the correct target environment.

Once the package building step has completed, we can then send a test function to it with sam local invoke --event events/first_function_event.json and see the output.

In most cases, we'll just chain these two commands together, and send sam build -u && sam local invoke --event events/first_function_event.json

Expected output from sam build -u

Start a new discussion. All notification go to the author.