I love AWS Lambda. It's so easy to get a function up and running while AWS handles everything other than the code for you.

But where is your code actually executed? How does AWS do it?

Well, I took a deeper look and this is what Lambda's foundation is!

🧵👇🏻
1️⃣ Thinking about Lambda

We know that we can write a script that looks like below and then upload it to AWS while they take care of everything else.

And from simply looking at the code, it doesn't look like the usual API method we'd implement in Express. Image
We're exporting a function, so something else must take our code, import it, and handle everything else. 🤔

Conclusion number one:
Something must run our code.
We also know the infamous cold start issues, which became better over time but are still there. Sometimes the environment is shut down and then started again.

Conclusion number two:
Whatever runs our code can be shut down and started again.
Have you ever noticed that it's actually impossible to access anything on the host system other than the temp directory? If not, try to, and you'll see that the environment will prevent it.

Conclusion number three:
The environment is pretty secure.
2️⃣ Thinking About The Technology Lambda Is Based On

There are a few ways of how AWS could have implemented Lambda (taking into account its initial release year of 2014):

- Containerization
- Virtualization
- Something running on bare metal
We can quickly rule out "Something running on bare metal." AWS already had EC2 at that time and some good knowledge of virtualization.

It would not have made a lot of sense for AWS to step back from virtualization and not use their existing infrastructure.
They basically had everything in place to provision a virtual machine on the fly.

What about Containers, then?
They can be spun up quickly and disposed of again.

AWS could have taken the code, wrap it with something and then put it inside a container.
This would have been a great idea but also something completely new for AWS at that time.

Additionally, it would not explain the (old) cold start issues because containers are usually pretty fast to spin up.
What about virtualization, then?
It would make a lot of sense.

At the time of starting Lambda, AWS already had EC2 and all the infrastructure to provision a virtual machine on the fly. It would also explain why a lambda function being cold-started could sometimes take ...
... so long until it finally served a request. But how did they manage to reduce the cold start time?

Before we dive deeper, I'll give you the answer:
Lambda has, since its release, been based on virtualization technology. No fancy containers, nothing self-developed.
It simply made the most sense for AWS to do it exactly this way.

As you've read above, they had all the knowledge, and they had the infrastructure for provision.

All they had to add was something to wrap user functions and something to call them, as well as some ...
... supporting services which could handle eventing.

And now that we know that it's virtualization, we can look at what's exactly used nowadays!
3️⃣ Enter Firecracker

Firecracker is a virtualization technology, or better, a virtual machine monitor (VMM) developed at Amazon (now open-sourced) and written in Rust (🧡).

It's the engine powering all your Lambda functions.

firecracker-microvm.github.io
What Firecracker basically does is creating and managing a multitude of Linux Kernel-based Virtual Machines (KVMs), which are microVMs that are faster and more secure than traditional VMs.

The interesting thing about those microVMs is that they are actually on par with... Image
...containers regarding memory footprint and start-up time, all while offering even more security due to the advanced features KVM offers.

You can read more about KVM at the link below.

en.wikipedia.org/wiki/Kernel-ba…
Firecracker comes with a REST API used to create VMs, delete them, manage them, etc.

Whenever you create a new lambda function and upload your code, the Firecracker REST-API is called under the hood to create a microVM with your function's CPU and memory settings.
AWS keeps base images that contain language/runtime-specific bootstrap code.
This is the code that actually invokes your handler, passes it the request, and takes the response to return it to the caller.

And it is also the code where various metrics are measured...
...that are then used to calculate your bill.

You can imagine the code as containing an infinite loop, waiting for requests, passing them to your function, returning the response, and gathering execution metrics.
After Firecracker created a new microVM, including your language-specific runtime, your code is put into its /var/runtime/bin folder. This is the place where the bootstrap code resides, too.

Now your function is basically able to run and accept requests.
After a while, AWS will shut the VM down to save resources on their side.

This is, once again, a call to the Firecracker API.

Incoming requests, e.g., through API Gateway, lead to Firecracker being tasked to start the VM again, such that it can process the request.
And that's it so far for Firecracker and its job within AWS Lambda.
4️⃣ Surrounding Infrastructure And Supporting Services

There are, of course, many surrounding systems and services that do their work to make AWS Lambda what it is.

There are services and systems around Firecracker that make all those requests to its API.
Some services are routing the requests. Other services decide when to call Firecracker to shut a certain VM down or pause it and when to spin it up again.

And there are certainly a lot more services, like Queues, scheduling asynchronous messages, and much more.
5️⃣ A Conclusion

Especially the improvements of cold-starts within recent months and years made me initially guess that AWS made the switch from virtualization to containerization.
But as you see, I was wrong and stand corrected. I would not have guessed that using KVM was an appropriate answer to tackle those issues.
It's pretty interesting to see how AWS has gone to make Lambda what it is today, and even more interesting to see Firecracker and how it solves many problems serverless functions cause for service providers.
And that's it. This thread's over.

If you like threads like this one, a follow would mean the world to me! 💛🙏🏼

I try to create them regularly so that you can learn!

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Oliver Jumpertz

Oliver Jumpertz Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @oliverjumpertz

30 May
Okay, I'll give away another 30 copies of Pratham's cheat sheet collection.

If you can't afford or buy for some reason and still want to support @Prathkum, DM me your mail.

❗️ First come, first served ❗️

Answering and sending out might take some time!
I already have way more than 30 DMs. I will process them in the order I received them. 🙏🏻

Give me some time, I'll notify anyone who managed to get one. ☺️
This is your lucky day. Thanks to @Prathkum, I'll give away 20 additional ones!
Read 7 tweets
30 May
AWS Lambda added container support some time ago.

We're going to look into what this offer actually includes and how we could build a containerized Lambda function ourselves. 👨🏻‍🏫

Start your IDEs and open your AWS consoles because we're going in!

🧵👇🏻
1️⃣ AWS Lambda Previous To Container Image Support

Until recently, AWS Lambda only allowed you to write some code and upload a zip archive containing all files necessary to run your function.

Some frameworks eased up this process, but that's how it went.
Lambda also imposed some pretty strict limits, especially the 50MB default deployment size limit.

You could technically circumvent this limit by pulling more deployment dependencies from S3 or issuing an AWS Service Limits support request. But this wasn't the most...
Read 32 tweets
26 May
There are alternatives out there but Git is by far the most used version control management tool which makes it essential for most software developers.

This justifies taking a look at _some_ of the most essential git operations you will need as a developer!

🧵👇🏻
1️⃣ Create A New Repository

This is the most basic command you'll need. When you start a repository locally, your start with git init. git init
2️⃣ Clone A Repository

You can clone a remote repository to get a local copy of it. Your local repository is connected to the remote one, so you can pull in changes and push yours to it git clone <remoteUrl/>
Read 15 tweets
25 May
I wanted to quickly share my perspective as an interviewer when it comes to portfolio projects.

I see many people thinking way too long about what to build, which quickly becomes an issue for them.

They spend way longer thinking than actually building.

👇🏻
I'd rather see the same ToDo app over and over again, well-executed with everything I'd like such a project to have, than twenty exotic apps that you could well have started your own company with.

I don't know whether I'm a minority here, but as a developer, you are not ...
...a product designer. Your day job won't be to come up with new ideas. It's, of course, highly appreciated if you supply your ideas for the product we might be working on, but never mandatory.

So, what I try to say is: Spend more time executing and building.
Read 4 tweets
23 May
If you want to become a Web 3.0 developer, a structured approach can leverage your learning by a lot.

Let me give you a roadmap that will definitely lead you towards your goal!

🧵👇🏻
0️⃣ Prerequisites

You should know JavaScript and web development in general.

If you don't, you should take a step back at this point and learn about web development first.

There are so many awesome courses and tutorials out there. You won't have a hard time finding good ones.
1️⃣ Learn The Basics Of Blockchain

You need to know what you work with. Blockchains are an incredible piece of technology, but they also aren't trivial to learn.

You'll have to put some time into it to understand what you will later build on.
Read 22 tweets
22 May
If you want to get hired, become an expert in one thing first before you try to learn everything across the board.

There must be a reason someone wants to work with you or you to work for them. Someone needs to have a demand for your expertise.

1/4
The thing is that "expertise" or "being an expert" is often misunderstood.

It doesn't mean knowing everything in and out. It means that you have a level of knowledge in something that helps you to solve problems.

2/4
People need those problems solved, and they will happily pay you to do it for them.

If you can do this with some HTML and CSS knowledge and build what they need, you are indeed an expert.

3/4
Read 4 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(