eeRA Laboratory

AWS Lambda Fundamentals

Build your first serverless application using Amazon Web Services Lambda with step-by-step code examples and interactive demos.

Start Tutorial ➔ View Advanced Topics

Core Concepts

Lambda Functions

Execute code without provisioning servers, paying only for execution time.

Event-Driven

Triggers include HTTP requests, file uploads, database changes, and more.

Auto-Scaling

Automatically scales with your application's event load.

Cost-Efficient

Pay only for the compute time consumed ($0.20 per 1M requests).

Lambda handler function (Node.js)
exports.handler = async (event) => {
    console.log("EVENT:", JSON.stringify(event, null, 2));
    
    return {
        statusCode: 200,
        body: JSON.stringify({
            message: "Hello from Lambda!",
            input: event
        })
    };
};
                        

This is a basic Lambda function that logs incoming events and returns a JSON response. We'll add an API Gateway trigger in the next section to make it accessible via HTTP.

Create Your First Lambda Function

1

Initialize a Project

mkdir my-lambda-project cd my-lambda-project

Create a new directory for your Lambda project. This will organize your source code, configuration files, and dependencies.

2

Create Lambda Code

touch index.js

Create a main handler file with this basic function:

exports.handler = async (event) => {
    return {
        statusCode: 200,
        body: JSON.stringify({ hello: "world" })
    };
};
                        
3

Local Testing

npm install --save-dev aws-lambda-mock-context

Add this test code to index.js:

const context = require("aws-lambda-mock-context")();

require("./index").handler({}, context);
                        

Run with node index.js to simulate a Lambda execution.

4

Deploy to AWS

npm install -g serverless

Create serverless.yml and deploy using:

serverless deploy
                        

The CLI will create a new Lambda, IAM roles, and other required AWS resources.

Lambda Execution Visualizer

Useful Tools & Resources

AWS Console

aws.amazon.com

Serverless CLI

serverless.com

SAM CLI

docs.aws.amazon.com/sam/latest

API Gateway

aws.amazon.com/api-gateway

CloudFormation

aws.amazon.com/cloudformation

AWS Official Blog

aws.amazon.com/blogs

Ready to Launch?

Sign up for our AWS Lambda training workshops or access our complete course library with interactive labs.