🌩️ DevOps Day 4 — Creating Virtual Machines in AWS and Azure


🚀 Introduction

Welcome to Day 4 of our DevOps learning journey!
In the previous posts, we explored DevOps fundamentals, the lifecycle stages, and the role of virtualization in improving efficiency.

Today, we’ll take it one step further — learning how virtual machines (VMs) are created and managed in AWS and Azure, and how DevOps engineers use different automation tools and APIs to provision them efficiently.




☁️ Understanding the Cloud VM Concept

A Virtual Machine (VM) is a software-based computer that runs on physical hardware using a hypervisor.
Cloud providers like AWS and Microsoft Azure make it simple to launch and manage VMs (called EC2 instances in AWS and Virtual Machines in Azure) within minutes — without worrying about physical servers.

In DevOps, creating VMs automatically through scripts, templates, or code is part of a broader concept called Infrastructure as Code (IaC) — a key principle that enables automation, repeatability, and scalability.


🧱 AWS Free Tier Overview

Before diving in, AWS offers a Free Tier that’s perfect for learning and experimentation.
It includes:

  • t2.micro / t3.micro instance (1 vCPU, 1 GB RAM)

  • 750 hours per month for 12 months

  • Ideal for testing deployments, automation, and CI/CD scripts

You can explore this from the AWS Management Console or directly through the AWS CLI and APIs.


đŸ–Ĩ️ Creating an EC2 Instance — 5 DevOps Methods

1. 🧰 AWS Management Console (GUI)

This is the simplest, manual way:

  1. Log in to your AWS Console

  2. Navigate to EC2 → Launch Instance

  3. Choose an AMI (Amazon Machine Image)

  4. Select instance type (e.g., t2.micro)

  5. Configure key pair, security group, and network settings

  6. Click Launch

Great for beginners, but not suitable for automation.


2. đŸ’ģ AWS CLI (Command Line Interface)

DevOps engineers often automate VM creation using the AWS CLI:

aws ec2 run-instances \
--image-id ami-0abcdef1234567890 \
--count 1 \
--instance-type t2.micro \
--key-name MyKeyPair \
--security-group-ids sg-0123456789abcdef0 \
--subnet-id subnet-6e7f829e

✅ Benefits:

  • Reusable commands

  • Easy to integrate into shell scripts or CI/CD pipelines


3. ⚙️ AWS CloudFormation (Infrastructure as Code)

CloudFormation uses YAML or JSON templates to define infrastructure.
Once written, you can deploy the same configuration multiple times with consistency.

Example snippet:

Resources:
MyEC2Instance:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-0abcdef1234567890
InstanceType: t2.micro

Run via CLI:

aws cloudformation create-stack --stack-name MyStack --template-body file://template.yaml

✅ Benefits:

  • Version-controlled infrastructure

  • Repeatable and fully automated


4. 🐍 Boto3 (AWS SDK for Python)

Boto3 allows developers to create and manage AWS resources programmatically using Python scripts.

Example:

import boto3
ec2 = boto3.resource('ec2')
ec2.create_instances(
ImageId='ami-0abcdef1234567890',
MinCount=1,
MaxCount=1,
InstanceType='t2.micro'
)

✅ Benefits:

  • Integrates easily into automation frameworks

  • Ideal for dynamic or event-driven instance creation


5. 🧩 Terraform (HashiCorp IaC Tool)

Terraform is a multi-cloud IaC tool used widely in DevOps for provisioning and managing infrastructure.

Example main.tf:

provider "aws" {
region = "us-east-1"
}
resource "aws_instance" "example" {
ami = "ami-0abcdef1234567890"
instance_type = "t2.micro"
}

Deploy with:

terraform init
terraform apply

✅ Benefits:

  • Works across AWS, Azure, GCP

  • State management and dependency handling

  • Reusable modules for large-scale automation


🤖 AWS CDK (Cloud Development Kit)

AWS CDK allows engineers to define cloud resources using familiar programming languages like Python, TypeScript, or Java.

Example:

from aws_cdk import aws_ec2 as ec2, core
class MyEC2Stack(core.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs):
super().__init__(scope, id, **kwargs)
ec2.Instance(self, "MyInstance",
instance_type=ec2.InstanceType("t2.micro"),
machine_image=ec2.AmazonLinuxImage()
)

✅ Benefits:

  • “Code-first” infrastructure

  • High-level abstraction for complex setups

  • Great for integrating with DevOps pipelines


🔑 Authentication & API Calls

All these methods interact with AWS APIs.
Each request must be:

  • Valid — Correctly formatted with proper parameters

  • Authenticated — Using access key/secret key or IAM role

  • Authorized — IAM policies must allow the requested actions

Once verified, AWS provisions the requested resources — securely and automatically.


🧭 Azure Comparison

Azure offers similar VM provisioning options:

  • Azure CLI (az vm create)

  • ARM Templates (Azure Resource Manager)

  • Azure SDKs for Python or .NET

  • Terraform or Bicep

Although syntax and tools differ, the DevOps principles remain the same — automation, repeatability, and scalability.


🌟 Conclusion

Creating virtual machines through automation tools like CLI, CloudFormation, Boto3, Terraform, and AWS CDK empowers DevOps teams to manage infrastructure like code — fast, reliable, and error-free.

“The power of DevOps lies not in clicking through consoles, but in scripting the cloud to build itself.”

Comments

Popular posts from this blog

🧩 DevOps Day 1 — Fundamentals of DevOps

DevOps Day 23 — Multi-Stage Docker Builds & Distroless Images: Build Smaller, Safer Containers

🚀 DevOps Day 2 — Understanding the SDLC and the Role of DevOps Engineers