AWS Lambda: What it is, how to use, when to use, and when not to
Tags: lambda, aws, programming, beginners
Published: 2023-01-10 17:04:14

## What is is
AWS Lambda is a serverless, event-driven service that lets you run code without having to manage servers. Similar services includes Microsoft Azure and Google cloud functions.

### Advantages
Some advantages of using AWS Lambda includes:

- Pay-as-you-go: On AWS Lambda, you're only charged for the number of requests and the duration of your functions, this means you will only be paying for what you use, more pricing info at https://aws.amazon.com/lambda/pricing
- Auto-scaling: If there's already one request being handled, AWS Lambda will provide separate instances for concurrent requests, by default, your account will have a limit of 1,000 concurrent requests across all Lambda functions in a region, but if you need, you can request a quota increase, more info at https://docs.aws.amazon.com/lambda/latest/dg/lambda-concurrency.html
- Server-free: You won't have to provide nor manage the infrastructure of your Lambda function, just upload your code as a .zip file or container image and you're good to go

### Disadvantages and limitations
Lambda's got a lot of advantages, but it's not all roses, let's take a look at some disadvantages and some limitations of it:
- Server-free: Both an advantage and a disadvantage, why? It's simple if you need to have full control of the environment your code is running, Lambda won't offer you this option
- 10 GB Of temporary storage: On Lambda, you'll have up to 10 GB of temporary storage for your code, in most cases, it's going to be enough, but in some cases, you might need more(Large files like videos…).
- 15-minute limit timeout: 15 minutes is the maximum timeout you can set on your Lambda function, again, this will fit most functions, but for some, it may not be enough.
- Deployment package limit of 250MB for unzipped and 50MB for zipped packages, this makes AWS Lambda not a good fit for big applications.

## How to use it
After creating your AWS Account(I won't cover this process here), you can access the Lambda service, the first thing you're going to see is the following page:
![AWS Lambda service page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k54q4hjnv3a1fdmjgjl6.png)
There you'll have some examples with different technologies: .NET, Node.js, Go… looking at those examples, you'll realize it's pretty simple to set up your first Lambda function, to do so, let's click to create a function, after doing so, you'll see this screen:
![AWS Lambda creation page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a4roksj06twfesh8keex.png)
There, you'll be able to start your function with a simple hello world, use a blueprint or select a container image; then you'll have some more settings, like the name of your function, the runtime of your function… lets create our hello world example. 
After creating your first function, you'll be redirected to it, and have the following view:
![AWS Lambda function page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wirrjygdgdtir8ub5hdt.png)
there you'll see that it was generated a handler function for us, and that's the function Lambda will always execute, so you always gotta have a handler to be executed, that's how you'll handle your requests. Your function may deal with HTTP requests, WebSocket connections/messages… but we won't be covering this here. 
As you can see on the right-side, you can upload your code from a .zip file or from a S3 location, you can even code on the "Code source" section, make it your playground to discover what you can do with Lambda.

## When to use it, and when not to
Lambda is a great alternative if you don't need to have fully control of the environment your code is running and if your use respects Lambda's limitations, it will help you deploy faster and your code will be auto-scaling, thus not having to worry much about scaling it, also, you'll only pay what you use, and most times it's a really great deal.

When your project start getting bigger, Lambda may not be the best choice, that's because you might need more control over the environment your code is running or the running period might be so long, that would be worth it to go for an EC2 or else, you could still use Lambda for your micro-services though.
## Conclusions
There's a lot of advantages and disadvantages of using AWS Lambda, it may or may not fit for your project, but I suggest you giving it a try nevertheless.
You can create some small projects to see what Lambda is capable of, after all, there's a free tier so you won't be charged for some small tests.
I hope I could bring you some insights on how you can use Lambda functions on your projects and the potential of it, and, hopefully, some of you may walk your first step towards using Lambda functions.