Amazon EC2 Instances or AWS Lambda Functions?

Stéphane Noutsa
4 min readJun 27, 2023

--

Amazon EC2 vs AWS Lambda

Once upon a time, in the enchanted world of cloud computing, there were two services, Amazon EC2 and AWS Lambda, that were always in competition with each other. Each believed they were the best and, often disagreed about who should handle specific computing workloads.

The first contender in this tale of the cloud world is Amazon Elastic Compute Cloud (EC2), which was launched first (August 2006) and has been around much longer.

Now, EC2 is kind of like a fancy hotel, where you can rent a room for as long as you need, and you’re responsible for bringing all your stuff and doing all the chores yourself.

On the other hand, AWS Lambda is more like a hotel with a very attentive staff. They give you a room, take care of all your needs, and when you’re done, you just leave! You don’t have to worry about bringing your luggage, doing your laundry, or even cleaning up after yourself.

Now, initially, both services believed they could handle any workload that came their way. But slowly, they started to discover the areas where they truly stood out from each other.

For instance, EC2 is great when you need to run a big, complex application that requires a lot of dedicated resources and an extended period to complete. Take the example of a group of developers working on a new software application. They require a lot of storage space, network connectivity, and computing power to run the application and put it through its paces. This kind of workload requires the ability to adjust resources and configurations, which makes EC2 the best option.

AWS Lambda, on the other hand, is the perfect candidate when you only need to use computing resources for small units of time. It’s like asking the hotel staff to wake you up with a cup of coffee in the morning. You don’t need your laptop to boot up and run your email server, you only need it to send an email. This is where AWS Lambda comes into its own.

The serverless model of AWS Lambda means that you don’t have to worry about the underlying infrastructure and configuration of the resources. Instead, you can just upload your code, and AWS will take care of the rest. Despite being launched much later (November 2014), AWS Lambda quickly made a name for itself by providing a highly efficient means of executing code.

Of course, this didn’t sit well with EC2. They felt like AWS Lambda was encroaching on their turf. So they started pointing out the areas they believe their service far outdid AWS Lambda. This includes any workload that requires extensive data processing, storage, or networking requirements, which is EC2’s bread and butter.

For instance, let’s imagine that you’re running a machine-learning model for a project. EC2 is your perfect partner because it requires a lot of resources to train the algorithm correctly. The workflow includes installing and configuring libraries such as TensorFlow, PyTorch, and Scikit-learn, which would take up a considerable portion of your time. As for AWS Lambda, it is unsuitable for this kind of workload as it has a cold start time and a maximum execution timeout of 15 minutes. This means that it would take more time initially to spin up the computing environment before running the model, and the model will need to be trained within the 15-minute execution time limit.

But then, AWS Lambda was not going down without a fight. They soon discovered that their serverless offering is a perfect fit for any application that requires immediate scaling, such as real-time responses for sensors, IoT devices, and data exchanges.

For example, let’s say you want to build a chatbot that requires real-time responses and supports many concurrent users. You can use AWS Lambda to develop a scaled-up version of it. AWS Lambda can easily execute multiple concurrent instances of code per user and provide extremely low latency, ensuring a seamless user experience. With EC2, you would have to spin up extra instances whenever traffic increases or have fewer instances running when traffic is low, which can add significant administrative overhead (an autoscaling group could mitigate this issue though, especially if its launch template uses a custom AMI — Amazon Machine Image — that has all the requirements already pre-installed).

EC2 then took it a step further by highlighting the transparency of its service compared to AWS Lambda. They pointed out that EC2 gives you much more control over how your resources are configured, how applications are deployed, and the level of customization you can achieve.

AWS Lambda, on the other hand, takes care of most of the configuration details automatically, which also means relinquishing some control and flexibility in processes.

In conclusion, it’s essential to understand when to use each of these services based on their strengths. EC2 is the perfect candidate when you require a large data processing workload, extensive storage, and complex networking requirements. AWS Lambda, on the other hand, is ideal where you only need to execute small units of code and applications with immediate scaling requirements.
The bottom line is to choose the service that best matches your project’s specific requirements and enjoy the benefits of the cloud!

--

--

Stéphane Noutsa

DevOps Engineer | 4x AWS | Terraform | Ansible | Docker | Kubernetes