Batch 4: Cloud Ansible AWS & Azure Docker & Podman Apache & NGINX ← Full TOC

☁️ Chapter 39 — AWS

Complete AWS and Azure reference: EC2, S3, RDS, Lambda, VMs, Blob, AKS with CLI and SDK examples.
Part of The Direct Path to Linux Ubuntu — free for all.

2Topics
51+Commands
3Examples
FreeNo login
🟠 AWS Core Services 🔵 Azure Core Services ⚡ Examples

🟠 AWS Core Services

🟠 AWS Core ServicesEC2, S3, RDS, Lambda, IAM, VPC — essential AWS

🔵 Azure Core Services

🔵 Azure Core ServicesAzure VMs, Blob, SQL, Functions, AKS, App Service

⚡ Quick Examples

AWS vs Azure Quick Reference

Side-by-side equivalent services.

# AWS vs Azure — Equivalent Services
# Service Type      AWS                  Azure
# ──────────────────────────────────────────────────────
# Compute           EC2                  Virtual Machines
# Serverless        Lambda               Azure Functions
# Containers        ECS/Fargate          Container Instances
# K8s managed       EKS                  AKS
# PaaS              Elastic Beanstalk    App Service
# Object storage    S3                   Blob Storage
# Block storage     EBS                  Managed Disks
# File storage      EFS                  Azure Files
# CDN               CloudFront           Azure CDN
# DNS               Route 53             Azure DNS
# Load balancer     ALB/NLB              App Gateway / LB
# SQL managed       RDS                  Azure SQL Database
# PostgreSQL        RDS PostgreSQL       Azure DB for PG
# NoSQL             DynamoDB             Cosmos DB
# Cache             ElastiCache          Azure Cache for Redis
# Docker registry   ECR                  ACR
# Identity          IAM                  Azure AD / Entra ID
# Key management    KMS                  Key Vault
# Secrets           Secrets Manager      Key Vault Secrets
# Monitoring        CloudWatch           Azure Monitor
# Logging           CloudWatch Logs      Log Analytics
# Audit             CloudTrail           Activity Log
# IaC               CloudFormation       ARM Templates / Bicep
# CI/CD             CodePipeline         Azure DevOps
# VPN               Site-to-Site VPN     VPN Gateway
# Direct connect    Direct Connect       ExpressRoute
# Message queue     SQS                  Service Bus Queue
# Pub/sub           SNS                  Service Bus Topic
# WAF               WAF                  Application Gateway WAF
# DDoS              Shield               DDoS Protection
# Cost              Cost Explorer        Cost Management
# CLI               aws                  az
# SDK               boto3 (Python)       azure-sdk (Python)

AWS boto3 Common Operations

Python AWS SDK for EC2, S3, RDS, Lambda.

# pip install boto3
import boto3
import json

# ── EC2 ──────────────────────────────────────────────────────
ec2 = boto3.resource('ec2', region_name='us-east-1')
ec2c = boto3.client('ec2', region_name='us-east-1')

# List running instances
for instance in ec2.instances.filter(Filters=[{'Name':'instance-state-name','Values':['running']}]):
    name = next((t['Value'] for t in (instance.tags or []) if t['Key']=='Name'), 'unnamed')
    print(f"  {instance.id} {instance.instance_type:12} {instance.public_ip_address or 'no-ip':16} {name}")

# ── S3 ───────────────────────────────────────────────────────
s3 = boto3.client('s3')
# List buckets
for b in s3.list_buckets()['Buckets']:
    print(f"  s3://{b['Name']}")

# Upload with metadata
s3.upload_file('index.html', 'mybucket', 'index.html',
    ExtraArgs={'ContentType':'text/html','CacheControl':'max-age=86400','ACL':'public-read'})

# Download
s3.download_file('mybucket', 'data.json', 'local-data.json')

# Presigned URL (15 min)
url = s3.generate_presigned_url('get_object',
    Params={'Bucket':'mybucket','Key':'private.pdf'}, ExpiresIn=900)
print(f"Presigned: {url[:80]}...")

# ── RDS ──────────────────────────────────────────────────────
rds = boto3.client('rds', region_name='us-east-1')
for db in rds.describe_db_instances()['DBInstances']:
    print(f"  {db['DBInstanceIdentifier']} {db['DBInstanceStatus']} {db.get('Endpoint',{}).get('Address','')}")

# Create snapshot
rds.create_db_snapshot(
    DBInstanceIdentifier='mywebuniversity-db',
    DBSnapshotIdentifier=f"mywebuniversity-snap-manual")

# ── Secrets Manager ───────────────────────────────────────────
sm = boto3.client('secretsmanager', region_name='us-east-1')
secret = json.loads(sm.get_secret_value(SecretId='mywebuniversity/prod/db')['SecretString'])
print(f"DB Host: {secret.get('host')}")

# ── SQS ──────────────────────────────────────────────────────
sqs = boto3.client('sqs', region_name='us-east-1')
# Create queue
q = sqs.create_queue(QueueName='mywebuniversity-jobs')
queue_url = q['QueueUrl']
# Send message
sqs.send_message(QueueUrl=queue_url, MessageBody=json.dumps({'job':'process_course','id':42}))
# Receive messages
msgs = sqs.receive_message(QueueUrl=queue_url, MaxNumberOfMessages=10)
for msg in msgs.get('Messages', []):
    body = json.loads(msg['Body'])
    print(f"  Job: {body}")
    sqs.delete_message(QueueUrl=queue_url, ReceiptHandle=msg['ReceiptHandle'])

# python3 boto3_demo.py

Azure Python SDK

Python Azure SDK for VMs, Blob, Database.

# pip install azure-identity azure-mgmt-compute azure-mgmt-storage azure-storage-blob
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
from azure.storage.blob import BlobServiceClient
import os

SUBSCRIPTION_ID = os.environ['AZURE_SUBSCRIPTION_ID']
RESOURCE_GROUP  = 'mywebuniversity-rg'

cred = DefaultAzureCredential()

# ── Virtual Machines ─────────────────────────────────────────
compute = ComputeManagementClient(cred, SUBSCRIPTION_ID)
print("=== Virtual Machines ===")
for vm in compute.virtual_machines.list(RESOURCE_GROUP):
    status = compute.virtual_machines.get(RESOURCE_GROUP, vm.name, expand='instanceView')
    state  = status.instance_view.statuses[-1].display_status if status.instance_view else 'unknown'
    print(f"  {vm.name:20} {vm.hardware_profile.vm_size:20} {state}")

# ── Blob Storage ─────────────────────────────────────────────
conn_str = os.environ.get('AZURE_STORAGE_CONNECTION_STRING',
    'DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=key==;EndpointSuffix=core.windows.net')

blob_service = BlobServiceClient.from_connection_string(conn_str)
container    = blob_service.get_container_client('content')

# Upload
with open('index.html', 'rb') as f:
    container.upload_blob('index.html', f, overwrite=True,
        content_settings={'content_type':'text/html'})

# List blobs
print("
=== Blobs in 'content' container ===")
for blob in container.list_blobs():
    print(f"  {blob.name:40} {blob.size:10,} bytes")

# Download
blob_client = container.get_blob_client('index.html')
with open('downloaded.html', 'wb') as f:
    f.write(blob_client.download_blob().readall())

# ── Key Vault Secrets ─────────────────────────────────────────
from azure.keyvault.secrets import SecretClient
kv_url  = f"https://mywebuniversity-kv.vault.azure.net/"
kv      = SecretClient(vault_url=kv_url, credential=cred)
db_pass = kv.get_secret('db-password').value
print(f"DB password retrieved from Key Vault")

# python3 azure_demo.py