One of the first services offered by AWS, EC2 was launched in 2006, and there's no doubt that AWS has made its mark on the cloud market thanks to it. But what does this service do? What are its use cases? That's what we're going to look at in this article.
What is the AWS EC2 service?
The EC2 service, which stands for Elastic Compute Cloud, enables anyone to rent servers.
In the past, companies were obliged to have physical servers for various purposes, such as web hosting or database storage. However, these resources come at a cost.
There’s the cost of purchasing them, of course, but there’s also the cost of maintaining them.
With EC2, companies no longer need to worry about technical issues that could arise on their servers, AWS. This not only saves costs, it also saves time.
We also increase our time savings, with what we’ll call our machine configuration. If we had our own servers, we’d have to take time to configure them before they were up and running. With EC2, on the other hand, we have an operational machine in just a few clicks.
Finally, it’s still possible to reduce our costs by adapting to our needs, via a variety of packages. For example, let’s say we’re hosting a site and at the beginning of each month there’s a big influx of traffic. To keep the site running smoothly, we’d need more power, but once the heavy traffic is over, we can switch back to a less powerful machine.
What’s more, it’s just as easy to shut down our EC2 instance quickly when we no longer need it, and turn it back on again straight away. In this way, we save money because we only pay per use (pay as you go), a key concept in Cloud Computing. If we look at the different possibilities with an EC2 instance, we can see why EC2 uses the word Elastic.
Here’s an image showing the life cycle of an EC2 machine:
![](https://datascientest.com/en/files/2023/10/AWS-EC2-schema.jpg)
Key components of Amazon ECS
Amazon ECS is based on several key components that provide a robust platform for container orchestration. Understanding these components is essential for leveraging the service.
![](https://datascientest.com/en/files/2023/10/image2.png)
Cluster :​
This is a logical grouping of resources where ECS tasks are performed. These clusters can be made up of one or more EC2 instances, or you can opt for Fargate, a serverless option that manages resource provisioning for you.
Task :
A task is the smallest and most fundamental unit of work in Amazon ECS. Each task is an instance of a task definition and contains one or more containers that are deployed together on the same EC2 or Fargate instance.
Task definition :
These are templates for your tasks. They describe the parameters for containers that are launched together as a task. Parameters include information such as which image to use, how much CPU and memory to allocate to each container, which ports to open for your application, and much more.
Service :​
A service is used to manage long-term tasks. It maintains the desired number of simultaneous instances of a defined task in your cluster. If a task or service fails, the service schedules another task to replace it, thus maintaining the desired number of tasks in the service.
How do I launch an instance on AWS EC2?
As we said earlier, it only takes a few clicks to use a virtual machine, but let’s take a brief look at the various steps involved in starting up an EC2 instance.
The first step is to select the type. By type, we mean your machine’s operating system. We still have a choice, thanks to AMI (Amazon Machine Images). You can have an AMI of Linux type, for example Ubuntu, Fedora or even RedHat, but it’s also possible to have a virtual machine based on Windows Server, and soon we’ll even be able to have one based on macOS.
Once you’ve chosen the type, you need to determine the family of your machine. We need to choose the number of CPUs, RAM, storage type and processor. Within each family, instances are classified by size. The larger the size, the more powerful the machine. Below is an example of a machine name.
![](https://datascientest.com/en/files/2023/10/unnamed-9-1.png)
Other aspects remain to be configured, but we won’t go into them here, as the default settings suffice.
All our machine parameters are set. All that remains is to define the security parameters. It’s in this section in particular that we’ll see how to connect to it. There are two ways of doing this:
Using the SSH protocol, we’ll need to define a key pair.
By using the AWS Session Manager service, which will open a tab in your browser where you can operate on the instance.
And now you’re ready to use your EC2 instance!
Benefits of using Amazon ECS
This service offers a host of advantages for large-scale container management and deployment. Here are just a few of them:
![](https://datascientest.com/en/files/2023/10/benefices-amazon-ecs.png)
Ease of use :
This is a logical grouping of resources where ECS tasks are performed. These clusters can be made up of one or more EC2 instances, or you can opt for Fargate, a serverless option that manages resource provisioning for you.
Scalability :
A task is the smallest and most fundamental unit of work in Amazon ECS. Each task is an instance of a task definition and contains one or more containers that are deployed together on the same EC2 or Fargate instance.
Flexibility :
These are templates for your tasks. They describe the parameters for containers that are launched together as a task. Parameters include information such as which image to use, how much CPU and memory to allocate to each container, which ports to open for your application, and much more.
Safety :
Integrates with AWS Identity and Access Management (IAM), enabling you to define fine-grained permissions for each task. What’s more, ECS is compatible with AWS PrivateLink, enabling you to access your containers without exposing your traffic to the Internet.
Integration with the AWS ecosystem:
Amazon ECS integrates with many other AWS services, such as Elastic Load Balancing, Amazon RDS, AWS Lambda and S3. This enables smooth workflows and simplified application management.
Support for microservices :
Amazon ECS supports microservices architectures, making it easier to develop, deploy and scale complex applications.
Some examples of EC2 use
As we said earlier, a classic example of using an EC2 virtual machine is hosting a website. A case in point is DataScientest’s Studio, which lists the best learner projects. Behind this pretty page is simply an EC2 instance with, of course, a few code files.
We can also simply use it as a development environment. Once our tests are complete, we can shut down our machine completely, but also turn on a new one to test new functionalities.
In Data Science, especially Deep Learning, we need a powerful machine to train our model on large datasets, so we’ll be using EC2. Similarly, when we need to launch a python script that takes a long time to run.
Further information
We’ve seen that the possibilities of the EC2 service are limitless (apart from the wallet). However, it’s becoming more complicated to use only a virtual machine for certain functionalities, and we’re losing time solving errors we may encounter.
For example, we’ve said that it’s possible to use an EC2 instance to store our databases, but we may have difficulty maintaining it or operating on it, which is why AWS offers database-only services. We can mention RDS, which is used for relational databases, but there’s also DynamoDB, for a NoSQL database.
If you’d like to learn more about launching virtual machines with AWS, as well as the different services offered by AWS, you can take the DataScientest training course to become a certified Solution Architect.