Core Compute Services (Azure App Service vs. AWS EC2)
Mind Map Summary
- Goal: Run your application code in the cloud.
- The Service Models
- IaaS (Infrastructure as a Service)
- What: The cloud provider gives you the fundamental building blocks (virtual machines, networking, storage). You manage the OS, runtime, and application.
- Analogy: Leasing a plot of land. You can build whatever you want, but you’re responsible for everything from the foundation up.
- Example: AWS EC2, Azure Virtual Machines.
- PaaS (Platform as a Service)
- What: You provide your application code, and the cloud provider manages the entire underlying platform (hardware, OS, patching, runtime).
- Analogy: Renting a fully furnished apartment. You just bring your personal belongings (your code).
- Example: Azure App Service, AWS Elastic Beanstalk.
- IaaS (Infrastructure as a Service)
- Comparison: EC2 vs. App Service
- AWS EC2 (IaaS)
- Focus: Control & Flexibility.
- You Manage: The Virtual Machine, OS installation and patching, runtime installation, networking, security groups, and your application.
- Best For: Applications with specific OS requirements, legacy apps, or tasks requiring complete control over the environment.
- Azure App Service (PaaS)
- Focus: Developer Productivity.
- You Manage: Only your application code and some configuration.
- Best For: Most modern web applications and APIs.
- Key Features: Built-in CI/CD, auto-scaling, deployment slots, custom domains & SSL.
- AWS EC2 (IaaS)
Core Concepts
1. IaaS: AWS EC2 (Elastic Compute Cloud)
EC2 is one of the oldest and most fundamental services of AWS. It provides secure, resizable compute capacity (virtual servers) in the cloud. When you use EC2, you are responsible for almost everything. You choose the operating system (Windows or Linux), the instance size (CPU and RAM), and the storage. You must then configure the networking, install any necessary runtimes (like the .NET SDK), set up a web server (like Nginx or IIS), and deploy your code. This gives you maximum flexibility but also carries the highest management burden. You are responsible for OS patching, security updates, and maintaining the entire software stack.
2. PaaS: Azure App Service
App Service is a fully managed platform for building, deploying, and scaling web apps and APIs. When you use App Service, you essentially tell Azure, “Here is my .NET 8 code. Please run it for me.” Azure handles everything else: it provisions the servers, ensures the OS is patched, keeps the .NET runtime up to date, and provides a secure environment. This allows developers to focus entirely on writing application code instead of managing infrastructure. It comes with a rich set of features out-of-the-box, such as autoscaling (automatically adding more instances based on load), deployment slots (for blue-green deployments), and easy integration with CI/CD pipelines.
The Trade-Off: Control vs. Convenience
The choice between IaaS and PaaS is a classic trade-off.
- Choose IaaS (EC2) when you need granular control that a PaaS offering doesn’t provide. For example, if your application needs to run a specific version of Linux or requires custom software to be installed on the machine itself.
- Choose PaaS (App Service) for most standard web application workloads. The reduction in management overhead and the built-in features for scaling and deployment dramatically increase developer productivity and reduce the total cost of ownership.
Practice Exercise
Deploy a simple web application to both an Azure App Service and an AWS EC2 instance. Document the steps and compare the deployment complexity and configuration options.
Answer
Here is a high-level comparison of the deployment process for a standard ASP.NET Core web API.
1. Deploying to Azure App Service (PaaS)
- Prerequisites: An Azure account.
- Create App Service: In the Azure Portal, click “Create a resource” -> “Web App”.
- Configure:
- Give it a unique name (e.g.,
my-awesome-api-123
). - Select the Runtime stack (e.g.,
.NET 8
). - Select the Operating System (Linux or Windows).
- Choose a pricing plan (an App Service Plan).
- Give it a unique name (e.g.,
- Deploy: Click “Create”. Once the service is provisioned (usually 1-2 minutes), you can deploy your code. The easiest way is to use the Visual Studio “Publish” feature or set up a GitHub Action. You right-click your project, select “Publish,” target the App Service you just created, and Visual Studio handles the rest. You can also configure a CI/CD pipeline to deploy automatically on every push to your main branch.
- Done: Your application is live and accessible at
https://my-awesome-api-123.azurewebsites.net
.
- Complexity: Low. The process is guided, and the platform handles all the infrastructure setup. You are only concerned with your code and a few high-level settings.
2. Deploying to AWS EC2 (IaaS)
- Prerequisites: An AWS account.
- Create EC2 Instance: In the AWS Console, go to EC2 and click “Launch instance”.
- Configure VM:
- Choose an Amazon Machine Image (AMI), which is the OS template (e.g., Windows Server 2022).
- Choose an instance type (e.g.,
t2.micro
for the free tier). - Create or select a key pair (an SSH key for connecting to the instance).
- Configure a Security Group (the firewall). You must create rules to allow incoming traffic on Port 80 (HTTP) and Port 443 (HTTPS), as well as RDP (for Windows) or SSH (for Linux) so you can connect to it.
- Launch and Connect: Launch the instance. Once it’s running, use an RDP client or SSH to connect to the virtual machine.
- Configure the Server: Once connected to the VM, your work has just begun:
- Install the .NET Hosting Bundle (which includes the runtime and IIS support).
- Configure IIS: Create a new website, set up an application pool, and point it to a directory where you will deploy your code.
- Configure the Windows Firewall on the machine itself to allow web traffic.
- Deploy Code: Publish your application to a local folder, then copy the build artifacts (the
publish
directory) to the server and place them in the directory you configured in IIS. - Done: Your application is live and accessible at the public IP address of your EC2 instance.
- Complexity: High. This is a much more manual and error-prone process. You are responsible for every step, from configuring the firewall to installing the runtime and setting up the web server. While it offers complete control, it requires significantly more infrastructure knowledge and effort.