Azure Virtual machine & AWS EC2 Instance
Published: 2023-04-11 14:30:18

Hi, I am Arun Kumar Palani, Senior software engineer in Luxoft & Microsoft certified solution Architect - Associate level.

Note: This article provides detailed idea about how IAAS provides virtual machines and enable entire control to organization to set up their own security implementation and configuration. The audience require some knowledge about cloud IAAS. If not, no problem I'll give some idea about IAAS in introduction.

**<u>Introduction:</u>**

**<u>IAAS:</u>** It is a method for providing computing infrastructure as on-demand services. It is one of the three essential models for cloud services. In a fully outsourced, on-demand service model, the user purchases servers, software data centers, or network equipment and rents those resources. The resources are distributed as services, and it supports dynamic scalability. On a single piece of hardware, numerous users are typically supported.

In this article, I will explain step by step how to create an AWS EC2 instance in AWS portal and Azure virtual machine in Azure portal and its usage, advantages, disadvantages, and how to deploy a .NET application in an AWS EC2 instance and Azure virtual machine in detail from portal also through CLI.

**<u>AWS EC2 instance:</u>**

Amazon EC2 or Elastic Compute Cloud is an AWS service that offers highly scalable computing capacity. In AWS, servers are referred to as “instances”. Amazon EC2 provides you with virtual servers in the cloud.

**<u>Step 1: Create an AWS account.</u>**

To use AWS services, you need to have an AWS account. Visit aws.amazon.com and click on the Sign-Up button. You will be prompted to enter your personal details and payment information.

**<u>Step 2: Select the Region.</u>**

After creating an AWS account, log in to the AWS Management Console. Then select the region where you want your EC2 instance to be deployed. It’s important to choose a region that is close to your users.

**<u>Step 3: Launch an Instance.</u>**

To launch an instance, go to the EC2 dashboard and click on the Launch Instance button. You will be taken to a wizard that will guide you through the process of launching an EC2 instance.

**<u>a) Choose an AMI (Amazon Machine Image):</u>**

The first step is to choose an Amazon Machine Image (AMI), which is a pre-configured virtual machine image. An AMI contains the information necessary to launch instances, such as the operating system, application server, and applications. You can either choose a pre-configured AMI or create your own custom AMI.

**<u>b) Choose an Instance Type:</u>**

Next, choose an instance type based on the amount of CPU, memory, storage, and network connectivity you require. The instance types range from micro to large and come with different pricing options based on your usage.

**<u>c) Configure Instance Details:</u>**

In this step, you can choose to configure Instance Details like Number of Instances, Network settings, IAM Role, Shutdown behavior, etc. You can also add user data and configure the instance to run a script on startup.

**<u>d) Add Storage:</u>**

In this step, you can add storage to your instance. You can choose the type of storage you want, like Elastic Block Store (EBS) or Instance Storage and specify the size of the volume.

**<u>e) Configure Security Group:</u>**

In this step, you need to configure the security group for your instance. A security group acts as a virtual firewall that controls inbound and outbound traffic to your instances. You can create a new security group or select an existing one.

**<u>f) Review and Launch:</u>**

After configuring all the settings, review them to ensure they are correct. Once you’re satisfied with the configuration, click on Launch to launch the instance. You will be prompted to select a key pair, which is used to securely log in to your instance.

**<u>Step 4: Connect and Configure your Instance.</u>**

Once your EC2 instance is launched, you need to connect to it and configure it to meet your needs. This can be done using Remote Desktop Protocol (RDP) for Windows instances and Secure Shell (SSH) for Linux instances.

**<u>Usage of AWS EC2 instances:</u>**

EC2 instances can be used to host websites and web applications, process big data and machine learning workloads, or store data in databases. 
Below listed are few advantages that make EC2 instances popular among businesses.

**<u>Advantages:</u>**

**<u>Scalable:</u>** EC2 instances can scale up or down based on demand without any downtime, which helps businesses save money by paying only for the resources they use.

**<u>Easy Deployment:</u>** Setting up an EC2 instance is fast and easy using the console dashboard or API integration.
Security: AWS offers comprehensive security features to protect data and applications hosted on EC2 instances.

**<u>Reliability:</u>** EC2 instances are designed for high availability and offer a 99.99% uptime Service Level Agreement (SLA).

**<u>Cost-Effective:</u>** With EC2 instances, there are no upfront costs or long-term commitments, and users pay only for what they use.

**<u>Disadvantages:</u>**

Though AWS provides many benefits with the EC2 instances, it has a few challenges as well. Few challenges are listed below:
Steep Learning Curve: The platform has a high learning curve, especially for beginners or companies unfamiliar with cloud infrastructure.

**<u>Complexity:</u>** Setting up a complex network requires good knowledge of networking concepts.

**<u>Create an AWS EC2 instance through CLI.</u>**

**<u>Install and configure the AWS CLI:</u>**

To install the AWS CLI, visit the AWS documentation page and follow the instructions for your operating system. Once installed, open a terminal window and run **‘aws configure’** to provide your AWS credentials.

**<u>Choose an Amazon Machine Image (AMI):</u>**

Determine which Amazon Machine Image (AMI) you want to use as the basis for your instance. You can use one of the default Amazon AMIs, or create your custom AMI.

**<u>Choose an instance type:</u>**

Select the instance type that best suits your requirements based on the number of CPUs, memory, and storage.

**<u>Create a key pair:</u>**

A Key Pair is used to SSH in your instance. You can create a new key pair using the following command:

**$ aws ec2 create-key-pair --key-name my-keypair --query 'KeyMaterial' --output text > my-keypair.pem**

**<u>Create a security group:</u>**

A Security Group acts as a virtual firewall for your instance. You can create a security group using the following command:

**$ aws ec2 create-security-group --group-name my-security-group --description "My security group"**

**<u>Configure inbound rules:</u>**

Inbound rules control the traffic that’s allowed to reach your instance. You can add inbound rules using the following command:

**$ aws ec2 authorize-security-group-ingress --group-name my-security-group --protocol tcp --port 22 --cidr 0.0.0.0/0**

This example allows all IP addresses to connect to your instance over port 22.

**<u>Launch the instance:</u>**

Finally, launch the EC2 instances using the following command:

**$ aws ec2 run-instances --image-id ami-xxxxxx --count 1 --instance-type t2.micro --key-name my-keypair --security-group-ids my-security-group --subnet-id subnet-xxxxxx**

Replace ‘ami-xxxxxx’ with the ID of your chosen AMI, and ‘subnet-xxxxxx’ with your VPC subnet ID.

**<u>Deploying .NET Application in AWS EC2 instance:</u>**

To deploy a .NET application in an AWS EC2 instance, follow the below steps:

**<u>Step 1: Create an EC2 Instance.</u>**

Follow the steps and launch an EC2 instance. Choose an Amazon Machine Image (AMI) that is compatible with the version of the .NET framework you intend to use.

**<u>Step 2: Install IIS.</u>**

IIS (Internet Information Services) is a web server that can be installed on Windows Server OS to host web applications. You can install IIS from the Server Manager UI or PowerShell command-line.

**<u>Step 3: Configure Access to Your Application.</u>**

Once IIS is installed, configure access to your application by setting up security groups and enabling HTTP/HTTPS access through the inbound rules.

**<u>Step 4: Publish Your .NET Application.</u>**

To publish the application, use Visual Studio’s publish wizard or use Azure DevOps pipeline to automate the deployment process.

**<u>Step 5: Test Your Application.</u>**

Verify that the application is running by navigating to the public IP address of the instance in a web browser.

**<u>Step 6: Automate Deployment Process.</u>**

Automating the deployment process using tools like Jenkins or AWS Code Deploy allows for continuous integration and delivery which improves productivity and reduces downtime.

Amazon EC2 provides highly scalable computing capacity in the cloud, which makes it an excellent platform for businesses of all sizes. EC2 instances can be used to host websites, run applications, process big data and stored in databases. However, companies must also be aware of the challenges associated with using AWS services.

We have now seen how to create an AWS EC2 instance, its usage, advantages, disadvantages, and how to deploy a .NET application in an AWS EC2 instance. Proper planning, implementation, and maintenance of your AWS infrastructure can lead to cost savings, improved efficiency, and business growth.

**<u>Azure Virtual machines:</u>**

Azure Virtual Machines (VMs) allow users to create and manage virtual machines in the cloud. These VMs can run various operating systems and are used for a variety of purposes, such as running applications, hosting websites, or providing infrastructure for testing and development.

**<u>Step 1: Create an Azure account.</u>**

To use Azure services, you need to have an Azure account. Visit azure.microsoft.com and click on the Start Free button. You will be prompted to enter your personal details and payment information.

**<u>Step 2: Select the Region.</u>**

After creating an Azure account, log in to the Azure portal. Then select the region where you want your virtual machine to be deployed. It’s important to choose a region that is close to your users.

**<u>Step 3: Create a Resource Group.</u>**

A Resource Group is a logical container that holds related resources for an Azure solution. To create a resource group, navigate to the Resource Group option in the Azure portal and click on Add. Enter the name, region, and subscription details.

**<u>Step 4: Create a Virtual Machine.</u>**

To create a virtual machine, follow the steps below.

**<u>a) Choose Image and Size:</u>**

Select the Image and size for your virtual machine based on your requirements. Azure offers a variety of pre-configured images to choose from.

**<u>b) Configure Basic Settings:</u>**

Provide relevant names for your virtual machine, username, and password. You can also enable extensions, boot diagnostics, and a public IP address.

**<u>c) Configure Disks:</u>**

Configure the storage options for your virtual machine. Azure offers multiple disk types for different workloads.

**<u>d) Configure Networking:</u>**

Configure the network settings for your virtual machine, including virtual network setup, subnet configuration, public IP address allocation, and network security group rules.

**<u>e) Review + Create:</u>**

Once all the required configurations are completed, review your settings and click on create to create your virtual machine.

**<u>Step 5: Connect and Configure Your Virtual Machine.</u>**

After creating your Azure Virtual machine, connect to it using Remote Desktop Protocol (RDP) or secure shell (SSH), depending on the virtual machine’s operating system. Then proceed to configure it according to your requirements, such as installing applications, setting up firewalls, and configuring virtual networking.

**<u>Usage of Azure Virtual Machines:</u>**

Azure VMs are used for various purposes, including hosting websites, running applications, providing infrastructure for testing and development, data storage, and backup. 

Below listed are few advantages that make Azure Virtual Machines popular among businesses:

**<u>Advantages:</u>**

**<u>Scalability:</u>** Azure VMs can be scaled up or down based on demand without any downtime.

**<u>High Availability:</u>** Azure provides a Service Level Agreement (SLA) of 99.9% availability for VMs.

**<u>Security:</u>** Azure offers comprehensive security features to protect data and applications hosted on Virtual Machines.

**<u>Reliability:</u>** Virtual machines are designed for high availability and offer a 99.9% uptime Service Level Agreement (SLA).

**<u>Cost-Effective:</u>** With Azure Virtual machines, there are no upfront costs, long-term commitments, and you pay only for what you use.

**<u>Disadvantages:</u>**

Along with the advantages, Azure VMs have a few limitations as well. Few disadvantages are listed below:

**<u>Steep Learning Curve:</u>** The platform has a high learning curve, especially for beginners or companies unfamiliar with cloud infrastructure.

**<u>Complexity:</u>** Setting up a complex network requires knowledge of networking concepts.

**<u>Deploying .NET Application in Azure Virtual Machine:</u>**
**<u>Create an Azure virtual machine using CLI:</u>**

**<u>Install and configure the Azure CLI:</u>**

To install the Azure CLI, visit the Azure documentation page and follow the instructions for your operating system. Once installed, open a terminal window and run ‘az login’ to connect to your Azure account.

**<u>Create a resource group:</u>**
A Resource Group is a logical container that groups resources together for easy management. You can create a new resource group using the following command:

**$ az group create --name MyResourceGroup --location eastus**

**<u>Choose an image:</u>**

Determine which image you want to use as the basis for your instance. You can use one of the default Azure images or create your custom image.

**<u>Create a virtual network:</u>**

A Virtual Network is required by Azure to create a virtual machine. You can create a new virtual network using the following command:

**$ az network vnet create --resource-group MyResourceGroup --name MyVnet --address-prefix 10.0.0.0/16 --subnet-name MySubnet --subnet-prefix 10.0.0.0/24**

**<u>Create a public IP address:</u>**

You need a public IP address to access your virtual machine from the Internet. You can create a public IP address using the following command:

**$ az network public-ip create --resource-group MyResourceGroup --name MyPublicIP --dns-name mypublicip**

**<u>Configure inbound rules:</u>**

Inbound rules control the traffic that’s allowed to reach your instance. You can add inbound rules using the following command:

**$ az network nsg rule create --resource-group MyResourceGroup --nsg-name MyNSG --name ssh --protocol tcp --priority 1000 --destination-port-range 22 --access allow**

This example allows all IP addresses to connect to your instance over port 22.

**<u>Launch the instance:</u>**

Finally, launch the virtual machine using the following command:

**$ az vm create --resource-group MyResourceGroup --name MyVM --image UbuntuLTS --admin-username azureuser --generate-ssh-keys --vnet-name MyVnet --subnet MySubnet --public-ip-address MyPublicIP --nsg MyNSG**

Replace ‘UbuntuLTS’ with the ID of your chosen image.

**To deploy a .NET application in an Azure Virtual Machine, follow the below steps:**

**<u>Step 1: Create an Azure Virtual Machine.</u>**

Follow the steps and create an Azure Virtual Machine. Choose the image that is compatible with the version of the .NET framework you intend to use.

**<u>Step 2: Install IIS</u>**

IIS (Internet Information Services) is a web server that can be installed on the Windows Server Operating System to host web applications. You can install IIS from the Server Manager UI or PowerShell command-line.

**<u>Step 3: Configure Access to Your Application</u>**

Once IIS is installed, configure access to your application by setting up security groups and enabling HTTP/HTTPS access through the inbound rules.

**<u>Step 4: Publish Your .NET Application.</u>**

To publish the application, use Visual Studio’s publish wizard or use Azure DevOps pipeline to automate the deployment process.

**<u>Step 5: Test Your Application.</u>**

Verify that the application is running by navigating to the public IP address of the virtual machine in a web browser.

**<u>Step 6: Automate Deployment Process.</u>**

Automating the deployment process using tools like Jenkins or Azure DevOps allows for continuous integration and delivery which improves productivity and reduces downtime.

Azure provides highly scalable computing capacity in the cloud, which makes it an excellent platform for businesses of all sizes. Azure Virtual Machines can be used to host websites, run applications, process big data, and store data in databases. However, companies must also be aware of the challenges associated with using Azure services.

We have now seen how to create an Azure Virtual Machine, its usage, advantages, disadvantages, and how to deploy a .NET application in an Azure Virtual Machine. Proper planning, implementation, and maintenance of your infrastructure can lead to cost savings, improved efficiency, and business growth.

**<u>Comparison:</u>**
Azure and AWS are two of the most popular cloud services providers that offer a range of cloud-based services. A Virtual Machine (VM) in Azure is similar to an Elastic Compute Cloud (EC2) instance in AWS. Both Azure VMs and AWS EC2 instances provide on-demand computing, flexibility, scalability, and pay-as-you-go pricing models.

**<u>Computing Resources:</u>**

Azure Virtual Machines and AWS EC2 Instances provide users with the ability to configure CPU, memory, and storage resources based on their requirements. However, there are some differences between these two services.
In Azure, VMs can be configured with up to 128 vCPUs, while in EC2 you can configure up to 256 vCPUs.
Azure offers a premium SSD disk type that provides high IOPS at a lower cost compared to AWS EBS volumes.
AWS provides an additional compute resource option called Elastic GPU, which allows users to attach graphics acceleration to EC2 instances for performance-intensive workloads.

**<u>Operating Systems:</u>**

Both Azure Virtual Machines and AWS EC2 instances support a wide range of operating systems, including Linux and Windows. However, there are differences in how these services manage operating system images.
Microsoft Azure offers pre-configured images that are optimized for different workloads like SQL, Java or .NET applications.
Amazon Web Services, on the other hand, offers Amazon Machine Images (AMIs) for customers to launch EC2 instances. It also has an extensive marketplace where users can find and purchase pre-configured images.

**<u>Networking:</u>**

Azure and AWS both offer virtual network configurations that allow users to build complex networking architectures. However, there are differences in how they are implemented.

Azure’s networking architecture uses a more simplified approach called Azure Virtual Network (VNet). VNets are designed to work like traditional on-premises networks and provide connectivity between VMs within the same VNet. Traffic between VNets or public internet is routed through a virtual gateway.

AWS networking architecture allows users to define network security groups, subnets, and route tables based on their requirements. Users also could manipulate IP addresses in EC2 instances.

**<u>Pricing:</u>**

Both Azure Virtual Machines and AWS EC2 Instances offer pay-as-you-go pricing models. However, there are differences in how they are priced.

Azure offers discounts for users who pre-pay for their virtual machines or reserve instance capacity for one- or three-year terms.

AWS provides a more granular pricing model that allows users to choose different payment options for computing resources, storage, and data transfers.

**<u>Management Tools:</u>**
Azure and AWS offer several management tools that enable users to manage their virtual machines from a centralized location. However, there are some differences in the management tools they provide.

Azure provides the Azure portal, which allows users to manage services using a web-based interface.

AWS provides the AWS Management Console, which allows users to manage services using a web-based interface. It also provides command-line tools and APIs that allow access to advanced features.

**<u>Conclusion:</u>** If we are IAAS Azure VM and AWS EC2 instance it makes a big difference because we own all the controls from our side like VNet, Ip configuration and it provides security features. We need to be very careful if we are using IAAS there is a high chance of potential threats if we misconfigured some areas in IAAS. 

If you have any doubts and require help for using IAAS please drop a comment. Happy to help.

Stay tuned!!!