Cost control, security and reliability
Two things go wrong in the cloud more than anything else: surprise bills and security mistakes. Both are preventable with habits rather than heroics. This final lesson collects those habits, plus the reliability practices that keep systems running, organised around the Well-Architected frameworks that AWS, Google Cloud and Azure all publish.
Part 1: Cost control
Where the money goes
| Usually the biggest costs | Easy savings |
|---|---|
| VMs and databases running 24/7 | Right-size them; stop dev environments at night and weekends |
| Over-sized instances "just in case" | Check CPU/memory graphs; most servers use under 20% |
| Data transfer out to the internet and between regions | Use a CDN, keep traffic in one region, use VPC endpoints |
| NAT gateways (per hour and per GB) | VPC endpoints for S3/DynamoDB; one NAT for dev |
| Forgotten resources: unattached disks, old snapshots, idle load balancers, unused IPs | Tag everything, review monthly, delete what's unused |
| Logs kept forever | Set retention (e.g. 30 days) on log groups |
| Storage in the most expensive class | Lifecycle rules to cheaper classes |
Tags make costs visible
Tag every resource with at least project, env and owner, then turn those tags on as cost allocation tags to see the bill per project:
aws s3 mb s3://acme-reports-prod > /dev/null
aws s3api put-bucket-tagging --bucket acme-reports-prod --tagging 'TagSet=[{Key=project,Value=reports},{Key=env,Value=prod},{Key=owner,Value=asha}]'
aws sqs create-queue --queue-name jobs-dev --tags project=reports,env=dev,owner=ravi > /dev/null
aws ec2 create-volume --availability-zone ap-south-1a --size 50 --volume-type gp3 \
--tag-specifications 'ResourceType=volume,Tags=[{Key=project,Value=reports},{Key=env,Value=dev},{Key=owner,Value=ravi}]' > /dev/null
echo "--- everything belonging to the reports project:"
aws resourcegroupstaggingapi get-resources --tag-filters Key=project,Values=reports \
--query "ResourceTagMappingList[].ResourceARN" --output text | tr '\t' '\n' | sed -E 's/:[0-9]{12}:/:123456789012:/; s/vol-[0-9a-f]+/vol-…/' | sort
echo "--- unattached disks (paid for, but doing nothing):"
aws ec2 describe-volumes --filters Name=status,Values=available --query "Volumes[].[Size, VolumeType, Tags[?Key=='owner'].Value | [0]]" --output text--- everything belonging to the reports project: arn:aws:ec2:ap-south-1:123456789012:volume/vol-… arn:aws:s3:::acme-reports-prod arn:aws:sqs:ap-south-1:123456789012:jobs-dev --- unattached disks (paid for, but doing nothing): 50 gp3 ravi
That last query finds unattached volumes, a classic forgotten cost. Google Cloud uses labels and Azure tags the same way.
The tools
| Tool | AWS | Google Cloud | Azure |
|---|---|---|---|
| Budgets and alerts | AWS Budgets | Budgets & alerts | Cost Management budgets |
| Explore spending | Cost Explorer | Billing reports, BigQuery export | Cost analysis |
| Right-sizing advice | Compute Optimizer, Trusted Advisor | Recommender | Advisor |
| Anomaly detection | Cost Anomaly Detection | Anomaly detection | Cost anomaly alerts |
| Discounts for commitment | Savings Plans, Reserved Instances | Committed use discounts | Reservations, Savings Plan |
Cost Explorer from the CLI (example output from a real account):
aws ce get-cost-and-usage --time-period Start=2026-10-01,End=2026-11-01 --granularity MONTHLY \
--metrics UnblendedCost --group-by Type=DIMENSION,Key=SERVICE \
--query "ResultsByTime[0].Groups[].[Keys[0], Metrics.UnblendedCost.Amount]" --output text | sort -k2 -rn | head -5Amazon Relational Database Service 61.84
Amazon Elastic Compute Cloud - Compute 48.20
EC2 - Other 19.72
Amazon Virtual Private Cloud 14.60
AmazonCloudWatch 3.11("EC2 - Other" is mostly disks and data transfer; "Virtual Private Cloud" is usually NAT gateways and public IPv4 addresses, which are charged per hour.)
A monthly cost routine
- Check the bill by service and by tag. Anything new or growing?
- Delete unused resources (unattached disks, old snapshots, idle load balancers and IPs).
- Look at right-sizing recommendations for the biggest VMs and databases.
- For steady workloads running all month, buy a Savings Plan / committed use discount (30–70% cheaper).
- Make sure dev environments shut down out of hours (an EventBridge schedule or instance scheduler).
Part 2: Security
The checklist that prevents most cloud incidents:
| Area | Do |
|---|---|
| Identity | MFA everywhere; SSO with temporary credentials; no root/owner use; roles for software; least privilege (see IAM) |
| Network | Databases and internal services in private subnets; no SSH/RDP/database ports open to the internet; Session Manager / IAP / Bastion for admin access |
| Data | Buckets private with public access blocked; encryption at rest and in transit; backups tested; versioning on important buckets |
| Secrets | In Secrets Manager / Secret Manager / Key Vault, never in code, images or Git |
| Logging | Audit logs on in every account and region, sent to a separate, locked-down account/project |
| Detection | Threat detection (GuardDuty, Security Command Center, Defender for Cloud) with alerts to a human |
| Patching | Managed services where possible; automatic OS patching for VMs; scanned container images |
| Accounts | Separate accounts/projects/subscriptions for prod and dev; guardrails at the organization level |
Audit logs: who did what
CloudTrail (AWS), Cloud Audit Logs (Google Cloud) and the Activity Log (Azure) record every API call. Make sure a trail covers all regions and stores logs somewhere attackers can't delete them:
aws s3 mb s3://acme-audit-logs-2026 > /dev/null
aws cloudtrail create-trail --name org-audit --s3-bucket-name acme-audit-logs-2026 \
--is-multi-region-trail --enable-log-file-validation \
--query "[Name, IsMultiRegionTrail, LogFileValidationEnabled]" --output text
aws cloudtrail start-logging --name org-audit
aws cloudtrail get-trail-status --name org-audit --query "IsLogging" --output textorg-audit True True True
When something odd happens, the audit log answers "which identity did it, from which IP, when". A real lookup (example output):
$ aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=DeleteBucket \
--query "Events[].[EventTime, Username, CloudTrailEvent]" --output text | cut -c1-80
2026-11-20T14:02:11+05:30 ravi {"eventSource":"s3.amazonaws.com","sourceIPAddress":"203.0.113.44",...If credentials leak
- Deactivate the key or revoke the session immediately.
- Investigate with the audit logs: what did it do, and when?
- Clean up: delete anything the attacker created (crypto-mining VMs in unusual regions are typical); rotate other secrets that may be exposed.
- Fix the cause: move to roles and SSO, add secret scanning to your Git repositories.
Part 3: Reliability
| Practice | Why |
|---|---|
| Multiple availability zones for anything that matters | One data centre failing shouldn't stop you |
| Health checks + auto-scaling/auto-healing | Broken servers are replaced automatically |
| Managed services (databases, queues, load balancers) | The provider handles failover |
| Backups with tested restores, and point-in-time recovery for databases | Mistakes and corruption happen |
| Infrastructure as code | You can rebuild everything, even in another region |
| Monitoring and alerts on what users feel: errors, latency, saturation | Find problems before customers report them |
| Decide your targets: how long can you be down (RTO), how much data can you lose (RPO)? | Drives how much redundancy to pay for |
Multi-region setups (a standby or active copy in another region) protect against an entire region failing, which is rare, and cost significantly more. Most applications are well served by multi-AZ plus good backups and IaC.
The Well-Architected frameworks
All three providers publish a framework to review your design against. The pillars are nearly identical:
| Pillar | Asks |
|---|---|
| Operational excellence | Can you deploy, monitor and respond to incidents well? |
| Security | Identity, data protection, detection, response |
| Reliability | Does it recover from failures automatically? |
| Performance efficiency | The right resource types and sizes, scaling with demand |
| Cost optimisation | Paying only for what delivers value |
| Sustainability (AWS) | Using resources efficiently to reduce environmental impact |
The AWS Well-Architected Tool, Google Cloud's Architecture Framework and Azure Well-Architected Review are free questionnaires that turn these into a concrete list of improvements for your workload.
Clean up
aws cloudtrail delete-trail --name org-audit && echo "trail deleted"
for b in acme-audit-logs-2026 acme-reports-prod; do aws s3 rb "s3://$b" --force > /dev/null; done
aws ec2 describe-volumes --filters Name=status,Values=available --query "Volumes[].VolumeId" --output text | xargs -n1 aws ec2 delete-volume --volume-id
aws sqs delete-queue --queue-url "$(aws sqs get-queue-url --queue-name jobs-dev --query QueueUrl --output text)"
aws resourcegroupstaggingapi get-resources --tag-filters Key=project,Values=reports --query "length(ResourceTagMappingList)"trail deleted 0
Where to go next
- Get hands-on with a small real project: a static website on object storage + CDN, an API on Cloud Run or Lambda, a database, all built with Terraform.
- Take a foundational certification: AWS Cloud Practitioner, Google Cloud Digital Leader or Azure Fundamentals (AZ-900), then an associate-level one (AWS Solutions Architect Associate, Google Associate Cloud Engineer, Azure Administrator AZ-104).
- Continue with the Docker, Kubernetes and Terraform courses on this site.
Practice
- Tag three resources in your account and list them by tag.
- Find any unattached disks, old snapshots or unused public IPs, and delete them.
- Check that audit logging is on for every region you use.
- Write down the RTO and RPO for a project of yours, and whether the current design meets them.
1.Which of these often surprises people on their first cloud bill?
2.What's the point of tagging resources with project, env and owner?
3.An access key leaked. What's the right order?
4.What does running across multiple availability zones protect against?