AWS Lambda | How to run your code without a server
Tags: aws, lambda, serverless, function
Published: 2022-02-05 00:46:55

In this post I will tell you a bit more about how you can run your programs without the need to instantiate a server just for that. We are talking about a serverless architecture. For this I will introduce you to the AWS service called AWS Lambda.

I will also show you step by step, showing how simple it is to use the service, and also for free. 

<a href="http://www.youtube.com/watch?feature=player_embedded&v=ziLB2h0u3cQ" target="_blank">
<img src="http://img.youtube.com/vi/ziLB2h0u3cQ/0.jpg" alt="AWS Lambda Introduction" width="240" height="180" border="10" />
</a>

I will split this post into two main parts, Theoretical (this post) and Practical (a new post, link below).

However, I recommend that you don't skip the theoretical part, because this is exactly where I explain what AWS Lambda is all about. It's quick, so let's go.

Theoretical Part Contents:

- What is the AWS Lambda service?
- Free Usage Level
- AWS Lambda vs EC2 (Serverless vs Server)

Contents of the Practical Part in a new link:

- Step by step to create an AWS Lambda Function from scratch, with Amazon S3 triggers.

---

## What is the AWS Lambda service?

"AWS Lambda is a serverless, event-driven compute service that lets you run code for virtually any type of application or backend service without provisioning or managing servers." (source: [https://aws.amazon.com/pt/lambda/](https://aws.amazon.com/pt/lambda/))

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xe9xleo3m9hy0rxhv85c.png)

In other words, this service allows you to execute a certain code without worrying about machine instantiation, maintenance, server scaling, service installation, etc.

And in this case, another advantage is that you pay only for what you use, i.e. for each request and according to the size and time of execution.

When you have an instantiated server, you pay for the time that server is on air, even if you are not using it.

---

## Free Usage Level

There is a free tier to use the AWS Lambda service, where you can run up to 1 million requests per month, or up to 400,000GB/second per month.

Which is very helpful if you want to do testing or even run low workloads.

More up-to-date information:

[https://aws.amazon.com/pt/lambda/pricing/?loc=ft#Free_Tier](https://aws.amazon.com/pt/lambda/pricing/?loc=ft#Free_Tier)

---

## AWS Lambda vs EC2 (Elastic Compute Cloud), which is better?

This is not even a valid comparison, the answer here is "It depends". No one wants to hear "It depends" as an answer, but this is a case that needs analysis and varies a lot from scenario to scenario. So you have to analyze the architecture, the volumetry, usage, etc.

For example, if you use AWS Lambda to make some infrequent requests during the month, then it will certainly be "cheaper" than keeping an EC2 machine running 24/7, but that doesn't mean it is the best or the right thing. If on the other hand you have a service that has a high volume of access, with large workloads, it will probably be cheaper to have a good EC2 instance capable of supporting the workload, but again, it doesn't mean it's the best, it will depend a lot on the architecture.

And you need to take into consideration other variables like scalability, high availability and so on.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mu5cfmv3ceocy3325y0c.png)

If you want to know more about EC2 instances, here is a video where I talk about exactly that:

[[Step-by-Step] Amazon EC2 - How to Upgrade a Free Server on AWS](https://youtu.be/aAfivfL537A)

---

## Step by Step - Creating an AWS Lambda Function from scratch, using Amazon S3 triggers.

To keep the content from getting too long in this post, the practical part is separated in the post below:

[Step by Step - Creating an AWS Lambda Function from scratch using Amazon S3 triggers.](https://dev.to/pena/step-by-step-creating-an-aws-lambda-function-from-scratch-using-amazon-s3-triggers-280d)

---

Subscribe to my Youtube channel:
[Youtube: Pena Rocks](https://www.youtube.com/penarocks) 

Follow me on social networks:
Instagram: [https://www.instagram.com/pena.rocks/](https://www.instagram.com/pena.rocks/)
Twitter: [https://twitter.com/nandopena](https://twitter.com/nandopena)
LinkedIn: [https://www.linkedin.com/in/nandopena/](https://www.linkedin.com/in/nandopena/)

More Information:
[https://www.pena.rocks/](https://www.pena.rocks/)