How to test AWS Lambda function

Table of Content

If you as me and want to test some new feature on AWS but don’t have a time to read the tons of documentation.

That time I wanted to test a Lambda function which I created on AWS, but what to do next with it I didn’t know.

I suggest a short instruction with quick "how to".

Assume, you have a simple Lambda "Hello World!" or something more weighty

// 'Hello World!' nodejs12.x runtime AWS Lambda function
exports.handler = (event, context, callback) => {
  console.log('Hello, logs!');
  callback(null, 'great success');
};

I created this function through Terraform, but it doesn’t have matter, because further instruction is the same for all cases.

What you should do the next, go to the AWS console, Services - Lambda - Functions, select your function (hello_lambda in my case), and click Test button
file

You will get a pop-up window with next content. You can change values but don’t change structure of JSON. Enter the name of a test event, TestLambdaEvent for example, and click Create button
file

Scroll your window to Function code block and click Test button
file
If all is correct you will see Execution Result with detailed information about running you function.

So, it’s basic steps which you should to do to test your function.
You can get more additional information on Monitoring tab, but it will not be discussed here.

Related links:
Run a Serverless "Hello, World!"
Improved Testing on the AWS Lambda Console

Leave a Reply

Your email address will not be published. Required fields are marked *