- A Go AWS SDK example - Fri, Nov 11 2022
- Getting started with Jenkins - Tue, Aug 16 2022
- Pulumi vs. Terraform - Tue, Jul 5 2022
The three big cloud providers all have their own serverless infrastructure. Google has Google cloud functions, Azure has Azure functions, and AWS, which we will focus on, has AWS Lambda.
By working with AWS Lambda, we will learn what they are, how they work, and how they differ from using a standard server in the cloud with EC2.
By the end, you should have a strong understanding of serverless. Let's dive in!
What is serverless computing?
If we refer back to our opening statement, serverless computing is a model where the required resources are dynamically assigned without the need for the user to know which servers are involved. Our history of running applications has been on local computers, and while we have had few issues with building our applications in this way, it does bring its own problems.
The first issue we encounter is cost. This might involve buying physical servers or purchasing servers from a cloud provider. Over time, servers depreciate and become obsolete. When this happens, we have to look at upgrading or replacing them.
The next issue is something all areas of IT feel the pain of, and that is patching. Protecting your servers from security vulnerabilities and having to patch frequently is not an easy job to keep on top of. The concern of "Will this patch break my application? or "How long will my application be affected while patching?" are common questions to face. Patching is also a time-consuming task for IT folks as well.
Lastly, hardware failures are another common issue. Diagnosing server hardware failures and how to resolve and repair them takes time and money, which could be spent improving your applications.
AWS Lambda can take these issues away!
AWS Lambda is the serverless offering from Amazon. AWS Lambda provides the platform for you to run your code without the need to provision or manage servers. With AWS Lambda, you can run code with the language of your choice without the concern of additional administration. AWS Lambda provides high availability by performing all the tasks required to achieve this, with you just needing to upload your code.
You might hear the phrase Function as a Service (FaaS) used to refer to serverless. This is due to how the code is executed. You write a piece of code to perform a certain task, which is usually triggered by a response to an event. With AWS Lambda, CloudWatch is a popular choice for triggering your function.
AWS Lambda provides some great benefits over a service such as EC2. As we addressed above in What is serverless, you are no longer responsible for provisioning and managing servers, patching, and scaling. AWS takes care of all this for you with Lambda. When your code is triggered, AWS Lambda automatically takes care of and scales your application as needed. With each trigger, the code runs in parallel and separately, scaling up to the required size.
The cost is also much lower compared to EC2. With EC2, you pay for the time that the instance is running and, of course, the size of the instance. With AWS Lambda, you only pay for the call to the function. So, if you only call the function a few times, you are not paying for it to sit there idly, doing nothing while waiting.
Wait, no servers?
AWS Lambda still requires servers to run the code, but the management of the server is hidden from the user. The Lambda service runs in its own container. When we create a function in Lambda, it is packaged into a new container that is ready to be executed when called. Unless configured, the AWS Lambda container created for your package will run inside AWS's own environment.
Since AWS Lambda was introduced in 2014, it has grown continually more powerful and now runs for longer periods. With a maximum memory allocation of 10 GB and up to 6 vCPU cores, it is possible to create powerful serverless functions to tackle intense applications, such as machine learning.
AWS Lambda uses
Now that we have a better understanding of what serverless and AWS Lambda are, what sort of things are they good for? Here are a few examples where you might want to consider AWS Lambda:
- Cloud automation
Lambda is great at automating cloud tasks such as backing up databases, running tasks on a schedule or moving data to an S3 bucket.
- Log analysis
Formatting and parsing logs for easier readability, which can be helpful for troubleshooting.
- Serverless website
You can host a static website on S3 and use lambda to perform different tasks via an API gateway call.
- Chat bots
How about creating a chat bot, which could cut back support calls and customer waiting times.
Limitations of AWS Lambda
All this sounds great, but are there any drawbacks to working with AWS Lambda? There are a few things worth noting before jumping into production.
- Execution/Run time
A Lambda function can only run for a maximum of 15 minutes. This cannot be increased.
- The size of the code package
The size of a zipped Lambda package must not exceed 50 MB; once unzipped, it should not be larger than 250 MB.
AWS Lambda can run 1,000 functions concurrently in a single AWS account. However, Amazon does state that you can amend this if you contact its support.
- Cold starts
If you are calling your function for the first time or haven't run it for around 15 minutes, then you can suffer a small start time delay. The latency that could be incurred is around 5–10 seconds before the function starts.
I have tried to provide an introduction to serverless with the use of AWS Lambda in this article. We have explored the concepts of serverless by delving into what it is and how it works, with some ideas for use and potential limitations you might find. We looked at the advantages of AWS Lambda, with a focus on cost and not having to manage the underlying infrastructure.
Subscribe to 4sysops newsletter!
I do hope this has given you a sense of what serverless is and where it might provide benefits to you or your company. In my next post I will show you to to get started with AWS LAMBDA.
Want to write for 4sysops? We are looking for new authors.
Hey Mate, thanks for sharing about Lambda. I am learning Lambda these days and found it an awesome service from AWS. Just went through your post and found it very useful. Thanks Again!