AWS Lambda

AWS Lambda, is it the number 1 server less compute service?

Let us understand AWS Lambda

AWS Lambda

Introduction

AWS Lambda is a serverless compute service that allows you to run code without needing to consider servers. It enables you to concentrate on what’s most important, such as creating a great application. You incur charges solely for the compute time you utilize. Paying for what you use means that you only pay when your code is executing. It’s serverless compute. The code runs in response to events in AWS services, like adding or removing files in an S3 bucket, updating DynamoDB tables, or receiving HTTP requests from API Gateway. AWS Lambda is like the fairy godmother of compute services—your code runs without you lifting a finger to manage servers. It only springs into action when needed and can handle anything from a trickle of requests to a full-blown avalanche. The best part? You only pay for the time your code is working its magic. When it’s not running, your wallet gets a break too

How does AWS Lambda work?

Each Lambda function gets its own container. When you create a function, Lambda packages it up, launches it on a multi-tenant cluster managed by AWS, and gives it the RAM and CPU it needs. Once the function wraps up, AWS charges you based on the memory allocated and the time it took to run. AWS handles the entire infrastructure behind the scenes. You won’t see much of how it works, but that’s the beauty—you don’t have to worry about updating machines or dodging network issues. AWS has it all covered. Using AWS Lambda saves time on operational tasks since the service is fully managed. With no infrastructure to maintain, you can devote more time to working on application code. However, this trade-off means giving up the flexibility of managing your own infrastructure.

Lambda Architecture

Event Sources

The producer serves as the initial step in an event-driven architecture and is referred to as an event source within AWS Lambda architecture. The event source dispatches the event to a Lambda function and comes in diverse types.

  • A REST API method call can be made through an API gateway like AWS API Gateway or Apigee.
  • A CloudWatch Event triggers a Lambda function when an AWS resource’s state changes, like logging an EC2 instance state change.
  • A new record in a DynamoDB table stream triggers Lambda, which polls the stream and invokes the linked function with any record change.
  • An S3 event notification for a new or updated file can trigger a Lambda function.
  • A CloudWatch scheduler can trigger an event using a cron job.

Lambda function

The Lambda function lies at the core of the Lambda architecture in AWS. It empowers the implementation of a Function-as-a-Service approach. You simply write the business logic as a function and implement a handler method. The Lambda function receives events from event sources, processes them according to the defined logic, and subsequently publishes these events to other services.

When you deploy the function on the AWS Lambda service, it compresses the code into a zip file and uploads it to an S3 bucket. Upon invocation, the function retrieves the code from S3, extracts it, launches the instance, installs necessary dependencies, and runs the code.

Lambda supports several languages, including NodeJS, Java, Python, and GO. When a function connects to VPC resources, it takes around a minute to create the ENI at runtime.

Versioning & Alias

A function can have multiple versions or aliases. A version exists in two states: unpublished or published. When we make code or configuration changes, the unpublished version updates. Once we publish it, the version becomes a snapshot and can’t be altered.

An alias is a named resource that maps to a specific version. You can change the alias to point to a different version. For instance, you might create an alias named ‘Prod’ that maps to the version intended for production deployment.

Environment variables

Lambda has the capability to store credentials by utilizing environment variables. These variables can also store application configuration details, which can be accessed through the AWS SDK code. Additionally, users have the option to encrypt these variables using KMS CMKs (customer-managed keys).

Lambda monitoring

By default, Lambda functions send their log events to CloudWatch Logs. You only need to enable IAM access to this service. It creates a LogGroup for each function and groups them in several LogStreams based on function invocations. The function also sends metrics data to CloudWatch Logs, allowing you to build graphs and dashboards from these metrics. You can monitor invocation, performance, and concurrency metrics.

You can configure a Lambda function for X-Ray distributed tracing. For instance, if a Lambda function calls an S3 bucket, you can use X-Ray graphs and traces to see the latency performance of the S3 service response for GET and PUT calls.

Event consumers

Meet the third major player in an AWS Lambda architecture: event consumers. Lambda functions are great, but they can’t run the show alone. They need backup from various services like databases, messaging queues, streams, object storage, and even some 3rd-party stars like Stripe, Twilio, and PayPal. These services are the ones who consume the events that Lambda functions dish out. Think of them as the hungry crowd, including DynamoDB, S3, SQS, SNS, other Lambda functions, and any REST APIs, whether they’re chilling in AWS or hanging out elsewhere.

Conclusion

In conclusion, AWS Lambda is the superhero of serverless computing – swooping in to save the day with its incredible powers! With the ability to execute code without the need for managing servers, Lambda is like a magical genie granting your every computing wish. So, whether you’re a coding wizard or just a humble mortal in the tech world, Lambda has got your back. It zips, it uploads, it executes – all with a flick of its AWS wand! The Lambda function serves as the cornerstone of the Lambda architecture within AWS, enabling the adoption of a Function-as-a-Service paradigm. By defining business logic as a function and implementing a handler method, developers can seamlessly process events received from various sources. Subsequently, the function executes the logic and disseminates the outcomes to different services. Upon deployment to the AWS Lambda service, the function packages the code into a compressed format and uploads it to an S3 bucket. When triggered, the function retrieves the code from S3, unpacks it, initializes the instance, installs necessary dependencies, and executes the designated functionality. So, embrace the Lambda magic and let your coding adventures soar to new heights in the cloud!

Leave a Comment

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

Scroll to Top