DEV Community

Cover image for # Creating Virtual Machines on Cloud Platforms: AWS, Azure, and GCP
Aaditya Kediyal
Aaditya Kediyal

Posted on

# Creating Virtual Machines on Cloud Platforms: AWS, Azure, and GCP

Virtual machines (VMs) are the backbone of modern cloud infrastructure, enabling developers to deploy applications, test software, and manage workloads with ease. In this blog, we'll explore how to create virtual machines on three leading cloud platforms: AWS, Azure, and GCP. We'll provide code snippets and step-by-step instructions to get you started.

AWS (Amazon Web Services)

AWS offers a robust and scalable cloud computing environment. The Elastic Compute Cloud (EC2) service is commonly used to create and manage virtual machines.

Step-by-Step Guide to Creating an EC2 Instance

  1. Sign in to the AWS Management Console.
  2. Navigate to the EC2 Dashboard.
  3. Launch Instance:
    • Click on the “Launch Instance” button.
  4. Choose an Amazon Machine Image (AMI):
    • Select an AMI. For this example, we’ll use the Amazon Linux 2 AMI.
  5. Choose an Instance Type:
    • Select an instance type. The t2.micro instance is a good choice for beginners.
  6. Configure Instance Details:
    • Configure settings like the number of instances, network, and IAM role.
  7. Add Storage:
    • Specify the storage size and type.
  8. Add Tags:
    • Add tags to organize and manage your instances.
  9. Configure Security Group:
    • Configure firewall settings to control traffic to your instance.
  10. Review and Launch:
    • Review your settings and click “Launch”. Choose an existing key pair or create a new one for SSH access.

Code Snippet (AWS CLI)

Using the AWS CLI, you can launch an EC2 instance with a simple command:

aws ec2 run-instances \
    --image-id ami-0abcdef1234567890 \
    --count 1 \
    --instance-type t2.micro \
    --key-name MyKeyPair \
    --security-group-ids sg-0a1b2c3d4e5f6g7h8 \
    --subnet-id subnet-0ab1c2d3e4f5g6h7i
Enter fullscreen mode Exit fullscreen mode

Azure (Microsoft Azure)

Azure offers Virtual Machines (VMs) as part of its comprehensive cloud services. Azure VMs support a wide range of operating systems and configurations.

Step-by-Step Guide to Creating an Azure VM

  1. Sign in to the Azure Portal.
  2. Navigate to Virtual Machines.
  3. Create a New VM:
    • Click on the “Create” button and select “Virtual Machine”.
  4. Basics:
    • Fill in the basic information such as subscription, resource group, and VM name.
  5. Choose Image and Size:
    • Select the OS image and VM size. For this example, we’ll use Ubuntu Server 20.04 LTS and the Standard_B1s size.
  6. Administrator Account:
    • Set up an administrator account with a username and SSH public key.
  7. Disks:
    • Configure the OS disk and any additional data disks.
  8. Networking:
    • Configure the network settings including virtual network, subnet, and public IP.
  9. Management, Monitoring, and Advanced:
    • Configure optional settings as needed.
  10. Review and Create:
    • Review your settings and click “Create”.

Code Snippet (Azure CLI)

Using the Azure CLI, you can create a VM with the following command:

az vm create \
    --resource-group myResourceGroup \
    --name myVM \
    --image UbuntuLTS \
    --admin-username azureuser \
    --generate-ssh-keys
Enter fullscreen mode Exit fullscreen mode

GCP (Google Cloud Platform)

Google Cloud Platform provides Compute Engine for creating and managing virtual machines. GCP VMs offer high performance and flexibility.

Step-by-Step Guide to Creating a GCP VM Instance

  1. Sign in to the Google Cloud Console.
  2. Navigate to Compute Engine.
  3. Create an Instance:
    • Click on the “Create Instance” button.
  4. Configure Instance:
    • Set the instance name, region, and zone.
  5. Choose Machine Type:
    • Select a machine type. The e2-micro is suitable for small tasks.
  6. Boot Disk:
    • Choose an operating system image. For this example, we’ll use Debian GNU/Linux.
  7. Firewall Rules:
    • Enable HTTP and HTTPS traffic if needed.
  8. Create:
    • Click the “Create” button to launch the instance.

Code Snippet (gcloud CLI)

Using the gcloud CLI, you can create a VM instance with the following command:

gcloud compute instances create my-instance \
    --image-family debian-10 \
    --image-project debian-cloud \
    --machine-type e2-micro \
    --zone us-central1-a
Enter fullscreen mode Exit fullscreen mode

Conclusion

Creating virtual machines on AWS, Azure, and GCP is straightforward and can be accomplished using their respective management consoles or CLI tools. Each platform offers unique features and flexibility to cater to different needs and preferences. Whether you are a beginner or an experienced developer, these cloud platforms provide the tools necessary to deploy and manage your VMs efficiently.

Happy cloud computing!

Top comments (0)