Create Simple AWS Lambda Function & Invoke Manually

Create Simple AWS Lambda Function & Invoke Manually


In this article, we will create a Lambda function using the AWS Lambda console. Then, we manually invoke the Lambda function using sample event data. AWS Lambda will execute the Lambda function and returns results. At last we will verify execution results, Lambda function and  CloudWatch metrics. In our next article we will see, how to trigger AWS Lambda function from AWS resource S3.

Don't Want To Read? Watch Video:


Lets follow below steps to create and invoke a simple basic Lambda function.

1. Log in to the AWS Management Console and open the AWS Lambda service panel.




2. Click on "Create function" button

3. Then select option "Author from scratch" as we want to create a simple function.



4. Now fill up the basic information as follows:

Function name: Enter your Lambda function name. It can be any name but use only letters, numbers, hyphens, or underscores with no spaces.

Runtime: choose Python / Node.js (You can choose any version as per your requirement)

Execution role: select "Create new role from template(s)"

Role name: Enter a name for your role. But use only letters, numbers, hyphens, or underscores with no spaces

Policy templates: Leave field blank for now. For the purposes of this basic "hello world" program our Lambda function will have the necessary execution permissions.



5. Click on "Create Function" button.

Now we have created a Lambda function successfully.

See in "Function code" section, It simply returns a text "Hello from Lambda".



Handler text box shows "lambda_function.lambda_handler" value. The format is like "filename.handler-function". The console saves this sample code in the "lambda_function.py" file and in the code lambda_handler is the function name that receives the event as a parameter when the Lambda function is invoked manually or automatically from other AWS resources.

Lets follow the below steps to test this Lambda function by triggering it manually.

1. Click on "Save" button

2. In the "Configure test event page", select "Create new test event" radio button and in "Event template", leave the default "Hello World" option. Enter an "Event name"



3. Click on "Create" button and then click on "Test" button.

4. Once you click on "Save" button AWS Lambda executes your function on your behalf

5. Now you will see successful execution result logs and CloudWatch logs



Happy Learning AWS Services!!!! :) Still Doubts? lets put your questions in below comment box! Thanks!

Please like and subscribe this channel. Your 1 subscription is very important to grow channel!






Create Simple AWS Lambda Function & Invoke Manually Create Simple AWS Lambda Function & Invoke Manually Reviewed by Web Technology Funda on 4:18:00 AM Rating: 5

No comments

Free! Free!Free! Subscribe to Get Free PHP (Magento) tutorial Update in Your Inbox!!! Hurry Up!!!