30. Introduction to AWS Lambda
Page 30 | Listen in audio
AWS Lambda is a compute service that lets you run code without provisioning or managing servers. It runs your code only when needed and automatically scales from a few requests per day to thousands per second. Therefore, it fits neatly into the category of serverless computing services offered by Amazon Web Services (AWS).
The first question that might arise is: why use AWS Lambda? The answer to that question is simple. AWS Lambda allows developers to focus on their code and business logic instead of managing the infrastructure. This is because AWS Lambda automatically manages the infrastructure to run your code in high availability.
In addition, AWS Lambda supports many popular programming languages including Python, Java, Go, PowerShell, Node.js, C#, Ruby, and even comes with a custom runtime environment. This means you can bring any programming language of your choice to AWS Lambda.
How does AWS Lambda work?
AWS Lambda runs your code in response to events. An event is any activity that occurs in your AWS environment. For example, a change to a file in an Amazon S3 bucket, an update to an Amazon DynamoDB table, an HTTP request via Amazon API Gateway, a state change in an AWS resource, a custom request you define, or any any other event you can imagine.
When one of these events occurs, AWS invokes your Lambda function. A Lambda function is a script or program that AWS Lambda runs in response to an event. In other words, a Lambda function is code that you run in AWS Lambda.
When AWS invokes your Lambda function, it passes information about the event to the function. Your function receives this information in an event object that AWS passes to the function as the first parameter. Your function can use the information in the event object to determine how to process the event.
Creating a Lambda Function
To create a Lambda function, you need to provide some information to AWS. This includes the function name, the programming language you are using (also known as the runtime environment), the function code, and some settings.
Once you've provided this information, AWS creates a runtime environment for your function. This runtime is an instance of the Linux operating system that includes everything your function needs to run your code. This includes the runtime environment you specified (for example, Python 3.7), any code or libraries your function uses, and any resources your function needs to run.
Running a Lambda Function
When an event occurs, AWS invokes your Lambda function to process the event. To do this, AWS creates an instance of your function's execution environment, loads your function code into that environment, and begins executing your code.
Your function code has an entry point, which is a function in your code that AWS calls when it invokes your Lambda function. This function takes two arguments: an event object, which contains information about the event that triggered the function, and a context object, which contains information about the execution environment.
Once AWS invokes your function, it is responsible for processing the event. This can include reading data from the event object, performing any kind of processing or computation, writing data to a database, sending a response to a client, and so on. AWS waits until your function has finished processing the event before considering the function invocation complete.
Conclusion
AWS Lambda is a powerful tool that allows developers to focus on writing code instead of managing servers. It provides a fully managed execution environment that scales automatically, allowing you to run your code in response to events at virtually any scale. If you're looking for a way to streamline your development workflow and reduce the time and effort required to manage infrastructure, AWS Lambda might be the solution you've been looking for.
Now answer the exercise about the content:
Which of the following statements is TRUE about AWS Lambda?
You are right! Congratulations, now go to the next page
You missed! Try again.
Next page of the Free Ebook: