Skip to main content

AWS Lambda: Power of Serverless Computing

AWS Lambda is a serverless compute service provided by AWS, allowing you to run code without provisioning or managing servers.

What Does Serverless Mean?​

The term serverless doesn’t mean there are no servers involved. It simply means that the servers running the code are managed by AWS, not by you. AWS handles everything from scaling to maintenance, letting you focus solely on writing and deploying your code.

Note

AWS Lambda runs functions based on events, which is why it is often referred to as "AWS functions."

Key Features of AWS Lambda​

Event-Driven Execution​

AWS Lambda executes your code in response to triggers such as changes in data, shifts in system state, or user actions. This event-driven model allows for highly reactive and efficient applications.

Automatic Scaling​

Lambda scales automatically by running code in response to each trigger. For example, if there's a flash sale and the number of incoming HTTP requests spikes, API Gateway routes these requests to the Lambda function. AWS Lambda automatically scales out, launching as many function instances as needed to handle the load.

Managed Resource Management​

AWS takes care of all the underlying servers running your code, handling provisioning, maintenance, and scaling. You don’t need to worry about managing infrastructure.

High Availability and Reliability​

Lambda functions are run in multiple Availability Zones (AZs) within a given AWS region. This ensures that your functions remain available even if one AZ experiences an outage, providing high availability.

Support for Multiple Programming Languages​

AWS Lambda supports a variety of programming languages, including Python, Node.js, Java, Go, Ruby, and .NET Core, making it flexible and adaptable to different development needs.

Cost-Efficiency with Pay-per-Use​

You only pay for the compute time your code actually uses, measured in milliseconds. This pay-per-use model makes AWS Lambda a cost-effective solution for many use cases.

Core Components of AWS Lambda​

Understanding the core components of AWS Lambda is crucial to effectively utilize its capabilities:

Event Source​

An event source is the entity that triggers the Lambda function. Lambda functions can be triggered by various AWS services or custom events.

Examples of Event Sources:

  • Amazon S3: Trigger a Lambda function on file uploads, deletions, or updates in an S3 bucket.

  • Amazon DynamoDB: Trigger a function when there are updates to DynamoDB tables.

  • Amazon SNS: Trigger a function upon receiving notifications.

  • Amazon API Gateway: Trigger a function on HTTP requests.

  • Amazon CloudWatch: Trigger a function based on scheduled events or specific log patterns.

Event Object​

This is the input data passed to the Lambda function when it’s invoked. It can include information about the event that triggered the function, such as details of the S3 object or DynamoDB table that caused the trigger.

Handler​

The handler is the function within your code that AWS Lambda calls to begin execution. It’s essentially the entry point for your Lambda function.

helloworld.py
def lambda_handler(event, context):
return "Hello, world!"

Runtime​

The runtime is the language-specific execution environment that runs your Lambda function. AWS Lambda supports several runtimes, including Python, Node.js, Java, Go, Ruby, and .NET Core.

Environment Variables​

These are key-value pairs that provide configuration settings to your Lambda function without hardcoding them into the code. They are useful for storing sensitive information (like API keys) or configuration settings.

Concurrency​

Concurrency refers to the number of instances of your function that can run simultaneously. AWS Lambda offers two types of concurrency:

  • Reserved Concurrency: Limits the maximum number of concurrent instances for your function, preventing overuse.

  • Provisioned Concurrency: Keeps a specified number of instances initialized and ready to respond to requests, reducing the delay associated with cold starts.

Visualizing AWS Lambda​

Note

When setting up S3 as an event source for AWS Lambda, ensure that the destination bucket is different from the source bucket to avoid recursive invocations of the Lambda function.