How Does AWS Lambda Work?
The AWS Lambda example with the block diagram below demonstrates how AWS Lambda works in a few simple steps:

Source - Link
Step 1: Upload your AWS Lambda code in any language that AWS Lambda supports. AWS Lambda functions support various languages, including Java, Python, Go, and C#.
Step 2: AWS Lambda can be triggered using the AWS services.
Step 3: AWS Lambda assists you in uploading code and the event data that should be used to trigger it.
Step 4: When prompted by AWS services, executes AWS Lambda Code:
Step 5: AWS only costs you when the AWS lambda code runs, not if it doesn't.
Create a lambda function with console
You develop a Lambda function via the console to start the exercise. Lambda's default code is used in this function. For non-compiled languages, the Lambda console has a code editor that allows you to modify and test code quickly. To upload your Lambda function code, you'll need to make an a.zip archive deployment package for compiled languages.
Create the function
Step 1: Login into your AWS account and click on "Sign in to the Console."
Step 2: Enter your login and password details.
Step 3: Select Lambda under "AWS Services"
Source - link
Step 4: Select options and click on the "Create Function" button
Function Type: Author from scratch
Name: lambdaBlog
Runtime: Node.js 10.x
Role: Choose an existing role / Create any custom rule
Existing Role: lambda_basic_execution

Source - link
Step 5: Now you will be able to see the below screen. Choose a way to upload/create code in the lambda function. 
Source - link
Step 6: Now, you can write your code in the editor provided. It runs on Nodejs, which we selected earlier.
Step 7: Handler name should be the same as your function name. This way, AWS knows which function to execute.
Step 8: We can add more options like execution timeout, environment variables, tags to group out our other functions, memory, etc.

source - link
Step 19: Click "Save."
Step 10: Now, copy the ARN number on the top right corner.

Source - link
Invoke the function
Invoke your Lambda function using the sample event data provided in the console.
To invoke a function
- After selecting your function, choose the Test tab.
- Select New event from the Test event menu. Leave the default hello-world option in Template. Give this test a name and take note of the following sample event template:
{
"key1": "value1",
"key2": "value2",
"key3": "value3"
}
-
Choose test after saving your changes. Per function, each user can create up to ten test events. Other users cannot access those test events. Lambda executes your function for you. The example event is received and processed by the function handler.
-
Upon successful completion, view the results in the console.
→ The status of the execution is shown as successful in the Execution result. Expand Details to see the outcomes of the function execution. The Log groups page in the CloudWatch interface is accessible via the logs link.
→ The Summary section shows the critical information reported in the Log output section (the REPORT line in the execution log).
→ Lambda's log for each invocation is displayed in the Log output section. These logs are written to CloudWatch by the function. These logs are displayed on the Lambda interface for your convenience. Go here to add logs to the CloudWatch log group and access the CloudWatch console's Log groups tab.
- Run the function (select test) a couple more times to get some metrics for the following step
- Select the Monitor option. This page displays graphs for the metrics sent to CloudWatch by Lambda.
Clean Up
Remove the example function once you've finished working with it. You can also remove the log group that contains the function's logs and the execution role that the console established.
To delete a Lambda function:
- Open the Functions page of the Lambda console.
- Choose a function.
- Choose Actions, Delete.
- Select Delete from the Delete function dialogue box.
To get rid of the log group:
- Open the CloudWatch console's Log groups page.
- Select the log group for the function (/aws/lambda/my-function).
- Select Actions, then Delete Log Group (s).
- Select Delete in the Delete log group(s) dialogue box.
To delete the execution role:
- Open the AWS Identity and Access Management (IAM) console's Roles page.
- Choose the function's function (my-function-role-31exxmpl).
- Select Delete Role.
- Select Yes, delete in the Delete role dialogue box.
With AWS CloudFormation and the AWS Command Line Interface, you can automate creating and cleanup functions, log groups, and roles (AWS CLI). See Lambda example applications for fully functional sample applications.
Pros and Cons of AWS Lambda

Frequently Asked Questions
What is AWS Lambda?
It's an Amazon Web Services serverless compute service that runs code in response to events and controls the compute resource autonomously.
What languages is AWS Lambda compatible with?
The languages supported by AWS Lambda are as follows: Python, Java, js, C#, Ruby, Go, and PowerShell.
What makes Lambda a time-saving approach?
There are specific reasons for this. The one is it's possible to store everything in the local server memory. Also, data can be stored directly in the database without affecting performance. In addition to this, testing is not much complicated. Integration testing can be made mighty through multiple vendors.
Conclusion
In this blog, we have given a detailed description of the AWS Lambda function, the complete steps of its working, the creation of the AWS Lambda function from the console, and the pros and cons in brief.
Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and Algorithms, Competitive Programming, JavaScript, System Design, Machine learning and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But if you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc; you must look at the problems, interview experiences, and interview bundle for placement preparations.
Nevertheless, you may consider our paid courses to give your career an edge over others!
Do upvote our blogs if you find them helpful and engaging!
Happy Learning!!