Skip to content

AWS Account Management & Billing

Chapter 2: AWS Account Management & Billing

Section titled “Chapter 2: AWS Account Management & Billing”

Mastering AWS Account Structure and Cost Management

Section titled “Mastering AWS Account Structure and Cost Management”

Understanding AWS account management and billing is crucial for DevOps engineers to maintain control over resources, security, and costs.

AWS Account Hierarchy
+------------------------------------------------------------------+
| |
| +------------------------+ |
| | Management Account | |
| | (Payer Account) | |
| | | |
| | - Consolidated Billing | |
| | - AWS Organizations | |
| | - Cost Explorer | |
| +-----------+------------+ |
| | |
| +-------------------+-------------------+ |
| | | | |
| v v v |
| +---------------+ +---------------+ +---------------+ |
| | Member Account| | Member Account| | Member Account| |
| | (Dev) | | (Test) | | (Prod) | |
| +---------------+ +---------------+ +---------------+ |
| | | | |
| v v v |
| +---------------+ +---------------+ +---------------+ |
| | OU-Dev | | OU-Test | | OU-Prod | |
| | (Dev Team) | | (Test Team) | | (Prod Team) | |
| +---------------+ +---------------+ +---------------+ |
| |
+------------------------------------------------------------------+

Account TypePurposeFeatures
StandardIndividual/Small teamsFull AWS access, basic support
OrganizationEnterpriseConsolidated billing, SCPs
GovCloudUS GovernmentFedRAMP compliance
ChinaChina operationsIsolated infrastructure
Account Type Architecture
+------------------------------------------------------------------+
| |
| Standard Account Organization Account |
| +----------------+ +------------------------+ |
| | | | Management Account | |
| | Single User | | | |
| | Single Bill | | +----------------+ | |
| | Basic IAM | | | Member Account 1| | |
| | | | +----------------+ | |
| +----------------+ | +----------------+ | |
| | | Member Account 2| | |
| | +----------------+ | |
| | +----------------+ | |
| | | Member Account N| | |
| | +----------------+ | |
| +------------------------+ |
| |
+------------------------------------------------------------------+

AWS Organizations Hierarchy
+------------------------------------------------------------------+
| |
| +------------------------+ |
| | Root | |
| | (Organization Root) | |
| +-----------+------------+ |
| | |
| +-------------------+-------------------+ |
| | | |
| v v |
| +---------------+ +---------------+ |
| | OU-Security| | OU-Workloads| |
| | | | | |
| | +---------+ | | +---------+ | |
| | |Security | | | |OU-Dev | | |
| | |Account | | | +---------+ | |
| | +---------+ | | +---------+ | |
| | +---------+ | | |OU-Test | | |
| | |Audit | | | +---------+ | |
| | |Account | | | +---------+ | |
| | +---------+ | | |OU-Prod | | |
| +---------------+ +---------------+ |
| |
| Key Concepts: |
| - Root: Top-level container |
| - OU (Organizational Unit): Group accounts |
| - SCP (Service Control Policy): Permission boundaries |
| - Member Accounts: Individual AWS accounts |
+------------------------------------------------------------------+
SCP Inheritance Model
+------------------------------------------------------------------+
| |
| +------------------------+ |
| | Root SCP | |
| | (Full AWS Access) | |
| +-----------+------------+ |
| | |
| Inherited down the tree |
| | |
| +-------------------+-------------------+ |
| | | |
| v v |
| +------------------------+ +------------------------+ |
| | OU-Production SCP | | OU-Development SCP | |
| | | | | |
| | ALLOW: EC2, RDS, S3 | | ALLOW: EC2, Lambda | |
| | DENY: IAM Delete | | DENY: RDS, Redshift | |
| | | | | |
| +------------------------+ +------------------------+ |
| | | |
| v v |
| +------------------------+ +------------------------+ |
| | Prod Account | | Dev Account | |
| | Effective Policy: | | Effective Policy: | |
| | Root SCP + OU SCP | | Root SCP + OU SCP | |
| +------------------------+ +------------------------+ |
| |
+------------------------------------------------------------------+
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyNonApprovedRegions",
"Effect": "Deny",
"NotAction": [
"iam:*",
"organizations:*",
"route53:*",
"support:*"
],
"Resource": "*",
"Condition": {
"StringNotEquals": {
"aws:RequestedRegion": [
"us-east-1",
"us-west-2",
"eu-west-1"
]
}
}
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PreventLeaveOrganization",
"Effect": "Deny",
"Action": "organizations:LeaveOrganization",
"Resource": "*"
}
]
}

Consolidated Billing Flow
+------------------------------------------------------------------+
| |
| Individual Billing (Without Organization) |
| +------------------------+ |
| | Account A: $500/month | |
| | Account B: $300/month | |
| | Account C: $200/month | |
| +------------------------+ |
| Total: $1000/month (separate bills) |
| |
| ============================================================ |
| |
| Consolidated Billing (With Organization) |
| +------------------------+ |
| | Management Account | |
| | (Payer Account) | |
| | | |
| | Account A: $500 | |
| | Account B: $300 | |
| | Account C: $200 | |
| | | |
| | Combined: $1000 | |
| | Volume Discount: -$50 | |
| | Final Bill: $950 | |
| +------------------------+ |
| |
| Benefits: |
| - Volume pricing discounts |
| - Single bill for all accounts |
| - Reserved Instance sharing |
| - Savings Plans sharing |
+------------------------------------------------------------------+
S3 Pricing Tiers (Example)
+------------------------------------------------------------------+
| |
| Storage Tier Price per GB |
| +----------------+-------------------+ |
| | First 50 TB | $0.023 per GB | |
| | Next 450 TB | $0.022 per GB | |
| | Over 500 TB | $0.021 per GB | |
| +----------------+-------------------+ |
| |
| Example: 600 TB storage |
| |
| Without Consolidation: |
| Account A (200 TB): 50×0.023 + 150×0.022 = $4.35 |
| Account B (200 TB): 50×0.023 + 150×0.022 = $4.35 |
| Account C (200 TB): 50×0.023 + 150×0.022 = $4.35 |
| Total: $13.05 |
| |
| With Consolidation: |
| Combined (600 TB): |
| 50×0.023 + 450×0.022 + 100×0.021 = $13.20 |
| (Better rate for over 500TB) |
+------------------------------------------------------------------+

AWS Cost Explorer Dashboard
+------------------------------------------------------------------+
| |
| +----------------------------------------------------------+ |
| | Cost Over Time | |
| | | |
| | $$$$$ | |
| | $ $$ | |
| | $ $$ $$$ | |
| | $ $$ $$$ $$ | |
| | $ $$ $$$ $$ $$ | |
| | |----|----|----|----|----| | |
| | Jan Feb Mar Apr May | |
| +----------------------------------------------------------+ |
| |
| +--------------------------+ +--------------------------+ |
| | Top Services by Cost | | Top Accounts by Cost | |
| | | | | |
| | EC2 $2,500 | | Prod Account $3,000 | |
| | RDS $1,200 | | Dev Account $1,500 | |
| | S3 $800 | | Test Account $500 | |
| | Lambda $300 | | | |
| +--------------------------+ +--------------------------+ |
| |
| Features: |
| - View costs by service, account, region |
| - Forecast future costs |
| - Create custom reports |
| - Set up anomaly detection |
+------------------------------------------------------------------+
AWS Budgets Configuration
+------------------------------------------------------------------+
| |
| Budget Types: |
| |
| 1. Cost Budget |
| +----------------------------------------------------------+ |
| | Budget Name: Monthly EC2 Budget | |
| | Budget Amount: $5,000 | |
| | Alert Thresholds: | |
| | - 70% ($3,500) -> Email to team | |
| | - 90% ($4,500) -> Email + SNS to Slack | |
| | - 100% ($5,000) -> Email + SNS + Auto Action | |
| +----------------------------------------------------------+ |
| |
| 2. Usage Budget |
| +----------------------------------------------------------+ |
| | Budget Name: S3 Storage Budget | |
| | Budget Amount: 10 TB | |
| | Alert Thresholds: | |
| | - 80% (8 TB) -> Email | |
| | - 100% (10 TB) -> Email + Auto Action | |
| +----------------------------------------------------------+ |
| |
| 3. RI/Savings Plans Budget |
| +----------------------------------------------------------+ |
| | Budget Name: RI Utilization | |
| | Target: 80% utilization | |
| | Alert: Below 70% utilization | |
| +----------------------------------------------------------+ |
| |
+------------------------------------------------------------------+
{
"ActionThreshold": {
"ActionThresholdType": "PERCENTAGE",
"ActionThresholdValue": 100
},
"ActionType": "APPLY_IAM_POLICY",
"BudgetName": "Monthly-EC2-Budget",
"Definition": {
"IamActionDefinition": {
"PolicyArn": "arn:aws:iam::aws:policy/AWSDenyAllEC2Actions",
"Roles": ["EC2LaunchRole"],
"Users": ["dev-user"]
}
},
"ExecutionRoleArn": "arn:aws:iam::123456789012:role/BudgetActionRole",
"ApprovalModel": "AUTOMATIC"
}

Right-Sizing Analysis
+------------------------------------------------------------------+
| |
| Under-utilized Instance Detection |
| |
| +------------------------+ |
| | Instance: i-12345 | |
| | Type: m5.xlarge | |
| | Cost: $140/month | |
| | | |
| | CPU Utilization: 15% | <-- Under-utilized! |
| | Memory: 30% | |
| | Network: 5% | |
| +------------------------+ |
| |
| Recommendation: |
| +------------------------+ |
| | Downsize to: | |
| | m5.large | |
| | Cost: $70/month | |
| | Savings: $70/month | |
| +------------------------+ |
| |
| Tools: |
| - AWS Cost Explorer (Right-sizing recommendations) |
| - AWS Compute Optimizer |
| - CloudWatch Metrics |
+------------------------------------------------------------------+

Strategy 2: Reserved Instances & Savings Plans

Section titled “Strategy 2: Reserved Instances & Savings Plans”
Pricing Models Comparison
+------------------------------------------------------------------+
| |
| On-Demand Pricing (Baseline) |
| +----------------------------------------------------------+ |
| | m5.xlarge (Linux) | |
| | $0.192/hour = $140.16/month = $1,681.92/year | |
| +----------------------------------------------------------+ |
| |
| Reserved Instance (1 Year, All Upfront) |
| +----------------------------------------------------------+ |
| | m5.xlarge (Linux) | |
| | $1,008/year = $84/month = $0.115/hour | |
| | Savings: 40% | |
| +----------------------------------------------------------+ |
| |
| Reserved Instance (3 Year, All Upfront) |
| +----------------------------------------------------------+ |
| | m5.xlarge (Linux) | |
| | $2,016/3-years = $56/month = $0.077/hour | |
| | Savings: 60% | |
| +----------------------------------------------------------+ |
| |
| Savings Plans (Compute) |
| +----------------------------------------------------------+ |
| | Commit $100/hour for 1 year | |
| | Applies to: EC2, Fargate, Lambda | |
| | Savings: Up to 72% | |
| +----------------------------------------------------------+ |
| |
+------------------------------------------------------------------+
Choose Your Savings Model
+------------------------------------------------------------------+
| |
| Start: Need Savings? |
| | |
| v |
| +---------------------+ |
| | Predictable | |
| | Workload? | |
| +----------+----------+ |
| | |
| +------------+------------+ |
| | | |
| v v |
| (Yes) (No) |
| | | |
| v v |
| +------------------+ +---------------------+ |
| | Single Service | | Use On-Demand | |
| | (EC2 only)? | | with Auto Scaling | |
| +--------+---------+ +---------------------+ |
| | |
| +--------+---------+ |
| | | |
| v v |
| (Yes) (No) |
| | | |
| v v |
| +--------+ +-------------+ |
| |Reserved| | Savings | |
| |Instance| | Plans | |
| +--------+ +-------------+ |
| | | |
| v v |
| +--------+ +-------------+ |
| |Up to 72%| | Up to 66% | |
| |savings | | (flexible) | |
| +--------+ +-------------+ |
| |
+------------------------------------------------------------------+
Spot Instance Usage Patterns
+------------------------------------------------------------------+
| |
| Spot Instance Pool |
| +----------------------------------------------------------+ |
| | Region: us-east-1 | |
| | Instance Type: m5.xlarge | |
| | | |
| | On-Demand Price: $0.192/hour | |
| | Spot Price: $0.038/hour (80% off!) | |
| | | |
| | Interruption Rate: <5% (varies) | |
| +----------------------------------------------------------+ |
| |
| Best Use Cases: |
| +----------------------------------------------------------+ |
| | - Batch processing jobs | |
| | - CI/CD pipelines | |
| | - Data analysis | |
| | - Image/video processing | |
| | - Distributed computing | |
| +----------------------------------------------------------+ |
| |
| NOT Recommended For: |
| +----------------------------------------------------------+ |
| | - Databases (critical) | |
| | - Production web servers | |
| | - Stateful applications | |
| | - Long-running jobs without checkpointing | |
| +----------------------------------------------------------+ |
| |
+------------------------------------------------------------------+
{
"SpotFleetRequestConfig": {
"IamFleetRole": "arn:aws:iam::123456789012:role/spot-fleet-role",
"AllocationStrategy": "diversified",
"TargetCapacity": 10,
"SpotPrice": "0.10",
"LaunchSpecifications": [
{
"ImageId": "ami-12345678",
"InstanceType": "m5.xlarge",
"KeyName": "my-key-pair",
"SubnetId": "subnet-12345678"
},
{
"ImageId": "ami-12345678",
"InstanceType": "m5.2xlarge",
"KeyName": "my-key-pair",
"SubnetId": "subnet-12345678"
}
]
}
}

Cost Allocation Tags Strategy
+------------------------------------------------------------------+
| |
| Tag Structure: |
| |
| +------------------------+ |
| | Key: Environment | |
| | Values: | |
| | - production | |
| | - staging | |
| | - development | |
| +------------------------+ |
| |
| +------------------------+ |
| | Key: Project | |
| | Values: | |
| | - project-alpha | |
| | - project-beta | |
| | - project-gamma | |
| +------------------------+ |
| |
| +------------------------+ |
| | Key: CostCenter | |
| | Values: | |
| | - cc-1001 | |
| | - cc-1002 | |
| | - cc-1003 | |
| +------------------------+ |
| |
| +------------------------+ |
| | Key: Owner | |
| | Values: | |
| | - team-backend | |
| | - team-frontend | |
| | - team-devops | |
| +------------------------+ |
| |
| Cost Report by Tags: |
| +----------------------------------------------------------+ |
| | Environment | Project | Cost | % of Total | |
| | ------------|--------------|---------|---------- | |
| | production | project-alpha| $5,000 | 50% | |
| | staging | project-alpha| $1,000 | 10% | |
| | development | project-beta | $2,000 | 20% | |
| | production | project-beta | $2,000 | 20% | |
| +----------------------------------------------------------+ |
| |
+------------------------------------------------------------------+
Terminal window
# AWS CLI - Tag Resources
aws ec2 create-tags \
--resources i-1234567890abcdef0 \
--tags Key=Environment,Value=production Key=Project,Value=alpha Key=Owner,Value=team-backend
# AWS CLI - Activate Cost Allocation Tags
aws ce tag-resource \
--resource-arn arn:aws:ce::123456789012:tagpolicy/default \
--tags Key=Environment,Value=production
# List all tags for a resource
aws ec2 describe-tags \
--filters "Name=resource-id,Values=i-1234567890abcdef0"

CloudWatch Billing Alarm Setup
+------------------------------------------------------------------+
| |
| Step 1: Enable Billing Metrics |
| +----------------------------------------------------------+ |
| | Go to Billing Console -> Billing Preferences | |
| | Enable: "Receive Billing Alerts" | |
| +----------------------------------------------------------+ |
| |
| Step 2: Create CloudWatch Alarm |
| +----------------------------------------------------------+ |
| | Namespace: AWS/Billing | |
| | Metric: EstimatedCharges | |
| | Currency: USD | |
| | Statistic: Maximum | |
| | Period: 6 hours | |
| +----------------------------------------------------------+ |
| |
| Step 3: Set Threshold |
| +----------------------------------------------------------+ |
| | Threshold: $100 | |
| | Comparison: GreaterThanThreshold | |
| | Evaluation Periods: 1 | |
| +----------------------------------------------------------+ |
| |
| Step 4: Configure Notification |
| +----------------------------------------------------------+ |
| | SNS Topic: billing-alerts | |
| | Subscribers: | |
| | - finance@company.com | |
| | - devops@company.com | |
| | - Slack webhook | |
| +----------------------------------------------------------+ |
| |
+------------------------------------------------------------------+
# SNS Topic for billing alerts
resource "aws_sns_topic" "billing_alerts" {
name = "billing-alerts"
}
resource "aws_sns_topic_subscription" "email" {
topic_arn = aws_sns_topic.billing_alerts.arn
protocol = "email"
endpoint = "devops@company.com"
}
# CloudWatch billing alarm
resource "aws_cloudwatch_metric_alarm" "billing" {
alarm_name = "billing-threshold-100"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = "1"
metric_name = "EstimatedCharges"
namespace = "AWS/Billing"
period = "21600" # 6 hours
statistic = "Maximum"
threshold = "100"
alarm_description = "Billing exceeds $100"
alarm_actions = [aws_sns_topic.billing_alerts.arn]
dimensions = {
Currency = "USD"
}
}

Cost Anomaly Detection Flow
+------------------------------------------------------------------+
| |
| Normal Pattern: |
| +----------------------------------------------------------+ |
| | $$$$$ | |
| | $ $$ | |
| | $ $$ $$$ | |
| | $ $$ $$$ $$ | |
| | |---|---|---|---|---| | |
| | Mon Tue Wed Thu Fri | |
| +----------------------------------------------------------+ |
| |
| Anomaly Detected: |
| +----------------------------------------------------------+ |
| | $$$$$ | |
| | $ $$ | |
| | $ $$ $$$ | |
| | $ $$ $$$ $$ $$$$$$$$$$$$ <-- ANOMALY! | |
| | |---|---|---|---|---|---| | |
| | Mon Tue Wed Thu Fri Sat | |
| +----------------------------------------------------------+ |
| |
| Alert Flow: |
| +----------------------------------------------------------+ |
| | 1. Anomaly detected by ML model | |
| | 2. Alert sent to SNS topic | |
| | 3. Notification to email/Slack | |
| | 4. Investigation triggered | |
| | 5. Root cause identified | |
| | 6. Remediation applied | |
| +----------------------------------------------------------+ |
| |
+------------------------------------------------------------------+

Terminal window
# Get current month's cost
aws ce get-cost-and-usage \
--time-period Start=2026-02-01,End=2026-02-28 \
--granularity MONTHLY \
--metrics BlendedCost
# Get cost by service
aws ce get-cost-and-usage \
--time-period Start=2026-02-01,End=2026-02-28 \
--granularity MONTHLY \
--metrics BlendedCost \
--group-by Type=DIMENSION,Key=SERVICE
# Get cost forecast
aws ce get-cost-forecast \
--time-period Start=2026-03-01,End=2026-03-31 \
--metric BLENDED_COST \
--granularity MONTHLY
# List budgets
aws budgets describe-budgets --account-id 123456789012
# List cost allocation tags
aws ce list-cost-allocation-tags
# Get reservation coverage
aws ce get-reservation-coverage \
--time-period Start=2026-02-01,End=2026-02-28 \
--granularity MONTHLY
import boto3
from datetime import datetime, timedelta
# Initialize Cost Explorer client
ce = boto3.client('ce')
# Get cost for last 30 days
end_date = datetime.now().strftime('%Y-%m-%d')
start_date = (datetime.now() - timedelta(days=30)).strftime('%Y-%m-%d')
response = ce.get_cost_and_usage(
TimePeriod={
'Start': start_date,
'End': end_date
},
Granularity='DAILY',
Metrics=['BlendedCost'],
GroupBy=[
{'Type': 'DIMENSION', 'Key': 'SERVICE'}
]
)
# Print costs by service
for result in response['ResultsByTime']:
print(f"\nDate: {result['TimePeriod']['Start']}")
for group in result['Groups']:
service = group['Keys'][0]
cost = group['Metrics']['BlendedCost']['Amount']
print(f" {service}: ${float(cost):.2f}")

Cost Management Best Practices
+------------------------------------------------------------------+
| |
| 1. Use AWS Organizations for consolidated billing |
| +----------------------------------------------+ |
| | Management Account -> Member Accounts | |
| | (Volume discounts, single bill) | |
| +----------------------------------------------+ |
| |
| 2. Implement tagging strategy from day one |
| +----------------------------------------------+ |
| | Required tags: Environment, Project, Owner | |
| | Enable cost allocation tags | |
| +----------------------------------------------+ |
| |
| 3. Set up budgets and alerts |
| +----------------------------------------------+ |
| | Monthly budget per environment | |
| | Alert at 70%, 90%, 100% | |
| +----------------------------------------------+ |
| |
| 4. Regular cost reviews |
| +----------------------------------------------+ |
| | Weekly: Review anomalies | |
| | Monthly: Review top costs | |
| | Quarterly: Review commitments | |
| +----------------------------------------------+ |
| |
| 5. Use Savings Plans/Reserved Instances |
| +----------------------------------------------+ |
| | For stable workloads: RI (up to 72% off) | |
| | For flexible workloads: Savings Plans | |
| +----------------------------------------------+ |
| |
+------------------------------------------------------------------+

Cost management is a core responsibility for DevOps engineers and SREs. In many organizations, the DevOps team is the primary owner of cloud spending.

FinOps in DevOps/SRE
+------------------------------------------------------------------+
| |
| DevOps Engineer Cost Responsibilities: |
| |
| 1. Infrastructure Cost Ownership |
| +----------------------------------------------------------+ |
| | - You provision it, you own the cost | |
| | - CI/CD pipelines consume compute resources | |
| | - Dev/staging environments often waste money | |
| +----------------------------------------------------------+ |
| |
| 2. Cost-Aware Architecture |
| +----------------------------------------------------------+ |
| | - Choosing Spot vs On-Demand for CI runners | |
| | - Right-sizing monitoring infrastructure | |
| | - Automating environment teardown (dev/staging) | |
| +----------------------------------------------------------+ |
| |
| 3. FinOps Practices |
| +----------------------------------------------------------+ |
| | - Weekly cost reviews in team standups | |
| | - Tagging enforcement in CI/CD pipelines | |
| | - Automated cost anomaly alerts to Slack/PagerDuty | |
| +----------------------------------------------------------+ |
| |
+------------------------------------------------------------------+

Terminal window
# Install AWS cost monitoring tools on Arch Linux
sudo pacman -S aws-cli-v2 jq python-boto3
# Quick daily cost check script
# Save as ~/bin/aws-cost-today.sh
#!/bin/bash
set -euo pipefail
TODAY=$(date -u '+%Y-%m-%d')
YESTERDAY=$(date -u -d 'yesterday' '+%Y-%m-%d')
echo "=== AWS Cost Report ==="
echo "Date: $YESTERDAY"
echo ""
# Get yesterday's cost by service
aws ce get-cost-and-usage \
--time-period "Start=$YESTERDAY,End=$TODAY" \
--granularity DAILY \
--metrics BlendedCost \
--group-by Type=DIMENSION,Key=SERVICE \
--query 'ResultsByTime[0].Groups[*].[Keys[0],Metrics.BlendedCost.Amount]' \
--output text | \
awk '{printf "%-40s $%.2f\n", $1, $2}' | \
sort -t'$' -k2 -rn | head -10
echo ""
echo "--- Month-to-Date Total ---"
MONTH_START=$(date -u '+%Y-%m-01')
aws ce get-cost-and-usage \
--time-period "Start=$MONTH_START,End=$TODAY" \
--granularity MONTHLY \
--metrics BlendedCost \
--query 'ResultsByTime[0].Total.BlendedCost.Amount' \
--output text | awk '{printf "Total: $%.2f\n", $1}'
# Set up as systemd timer for daily execution
# /etc/systemd/system/aws-cost-report.service
[Unit]
Description=Daily AWS Cost Report
[Service]
Type=oneshot
ExecStart=/home/akash/bin/aws-cost-today.sh
User=akash
Environment=HOME=/home/akash
# /etc/systemd/system/aws-cost-report.timer
[Unit]
Description=Run cost report daily at 9 AM
[Timer]
OnCalendar=*-*-* 09:00:00
Persistent=true
[Install]
WantedBy=timers.target
/usr/local/bin/aws-cost-alert.sh
# Cost alert script that sends to Slack/Discord
#!/bin/bash
THRESHOLD=100 # Alert if daily cost exceeds $100
SLACK_WEBHOOK="https://hooks.slack.com/services/YOUR/WEBHOOK/URL"
TODAY=$(date -u '+%Y-%m-%d')
YESTERDAY=$(date -u -d 'yesterday' '+%Y-%m-%d')
COST=$(aws ce get-cost-and-usage \
--time-period "Start=$YESTERDAY,End=$TODAY" \
--granularity DAILY \
--metrics BlendedCost \
--query 'ResultsByTime[0].Total.BlendedCost.Amount' \
--output text)
# Compare cost with threshold (using bc for floating point)
if (( $(echo "$COST > $THRESHOLD" | bc -l) )); then
curl -X POST -H 'Content-type: application/json' \
--data "{\"text\":\"⚠️ AWS Cost Alert: Yesterday's spend was \$$COST (threshold: \$$THRESHOLD)\"}" \
"$SLACK_WEBHOOK"
fi

Scenario 1: Runaway Costs from Forgotten Resources

Section titled “Scenario 1: Runaway Costs from Forgotten Resources”
Cost Incident: Orphaned Resources
+------------------------------------------------------------------+
| |
| Situation: |
| - Developer spun up 10x m5.4xlarge for load testing |
| - Forgot to terminate after testing |
| - Running for 3 weeks unnoticed |
| - Cost: ~$4,600 wasted |
| |
| Root Cause: |
| - No auto-shutdown policies |
| - No cost alerts configured |
| - No resource tagging enforcement |
| |
| Prevention: |
| +----------------------------------------------------------+ |
| | 1. Tag all resources with expiry dates | |
| | 2. Lambda function to terminate expired resources | |
| | 3. AWS Budget alerts at 50%, 80%, 100% | |
| | 4. SCPs to limit instance types in dev accounts | |
| | 5. Weekly cost review in team standup | |
| +----------------------------------------------------------+ |
| |
+------------------------------------------------------------------+
Enterprise Account Strategy
+------------------------------------------------------------------+
| |
| Management Account (Payer) |
| +----------------------------------------------------------+ |
| | - Consolidated billing only | |
| | - No workloads deployed here | |
| | - Budget alerts and cost anomaly detection | |
| +----------------------------------------------------------+ |
| | |
| +----+----+----+----+ |
| | | | | | |
| v v v v v |
| |
| OU: Security OU: Production |
| - Audit account - Prod workloads |
| - Log archive - RI/Savings Plans purchased here |
| - Security tools - SCP: No deleting CloudTrail |
| |
| OU: Development OU: Sandbox |
| - Dev environments - Experimentation |
| - SCP: Max m5.xlarge - Hard budget cap: $500/month |
| - Auto-shutdown at 7PM- SCP: Deny expensive services |
| |
| Key Savings: |
| - RI sharing across accounts saves ~30% |
| - Dev auto-shutdown saves ~60% on compute |
| - Consolidated billing volume discounts: ~5-10% |
| |
+------------------------------------------------------------------+

IssueCauseSolution
Unexpected high billForgotten resources, data transferUse Cost Explorer to identify, set up Budget alerts
Budget alerts not firingBilling metrics delayed ~6-8 hoursUnderstand the delay; use CloudWatch for real-time
Cost allocation tags not showingTags not activated in billingActivate tags in Billing console > Cost allocation tags
RI not applying to instancesWrong AZ, instance type, or platformVerify RI scope matches running instances
Cross-account RI sharing not workingRI sharing disabledEnable RI sharing in management account
Cannot see other account’s costsMissing permissionsNeed ce:GetCostAndUsage permission
Terminal window
# Debug billing issues from terminal
# Check if your tags are activated
aws ce list-cost-allocation-tags \
--status Active \
--query 'CostAllocationTags[*].[TagKey,Status]' \
--output table
# Find untagged resources (potential cost leaks)
aws resourcegroupstaggingapi get-resources \
--region us-east-1 \
--query 'ResourceTagMappingList[?Tags==`[]`].ResourceARN' \
--output text | head -20
# Check RI utilization
aws ce get-reservation-utilization \
--time-period "Start=$(date -u -d '30 days ago' '+%Y-%m-%d'),End=$(date -u '+%Y-%m-%d')" \
--query 'UtilizationsByTime[0].Total' \
--output table

Billing Anti-Patterns
+------------------------------------------------------------------+
| |
| ❌ Mistake 1: No Budget Alerts |
| +----------------------------------------------------------+ |
| | Problem: No visibility into spending until bill arrives | |
| | Impact: Surprise bills of $10,000+ | |
| | Fix: Set alerts at 50%, 80%, 100% of budget | |
| +----------------------------------------------------------+ |
| |
| ❌ Mistake 2: Buying RIs Too Early |
| +----------------------------------------------------------+ |
| | Problem: Purchasing 3-year RIs before usage stabilizes | |
| | Impact: Paying for unused capacity | |
| | Fix: Run On-Demand for 3 months, analyze, then commit | |
| +----------------------------------------------------------+ |
| |
| ❌ Mistake 3: Not Tagging Resources |
| +----------------------------------------------------------+ |
| | Problem: Cannot attribute costs to teams/projects | |
| | Impact: No accountability, no optimization targets | |
| | Fix: Enforce tagging via SCPs and CI/CD pipelines | |
| +----------------------------------------------------------+ |
| |
| ❌ Mistake 4: Running Dev/Staging 24/7 |
| +----------------------------------------------------------+ |
| | Problem: Non-production environments running at night | |
| | Impact: Wasting 65% of compute cost (16hrs/day idle) | |
| | Fix: Auto-shutdown Lambda or Instance Scheduler | |
| +----------------------------------------------------------+ |
| |
| ❌ Mistake 5: Ignoring Data Transfer Costs |
| +----------------------------------------------------------+ |
| | Problem: Microservices chatting across AZs/regions | |
| | Impact: Data transfer can be 20-30% of total bill | |
| | Fix: Co-locate services, use VPC endpoints | |
| +----------------------------------------------------------+ |
| |
+------------------------------------------------------------------+

  1. Q: What is AWS Organizations and why would you use it?

    • A: AWS Organizations lets you centrally manage multiple AWS accounts. Benefits: consolidated billing for volume discounts, SCPs for permission guardrails, centralized logging/auditing, and OU-based account organization. Essential for enterprises with separate dev/staging/prod accounts.
  2. Q: Explain the difference between Reserved Instances and Savings Plans.

    • A: RIs are tied to specific instance types and regions (up to 72% savings). Savings Plans are a commitment to hourly spend (up to 66% savings) but more flexible — they apply across instance families, regions, and even across EC2/Fargate/Lambda. Use RIs for predictable, single-service workloads; Savings Plans for varied workloads.
  3. Q: How do you implement cost controls in a multi-account AWS environment?

    • A: Use AWS Organizations with OUs. Apply SCPs to restrict expensive services in dev accounts. Set up AWS Budgets with auto-actions. Enforce tagging policies. Enable Cost Anomaly Detection. Share RIs across accounts via consolidated billing. Schedule dev environment shutdowns.
  1. Q: Your AWS bill jumped 40% this month. How do you investigate?

    • A: Start with Cost Explorer to identify which service/account/region increased. Check Cost Anomaly Detection for flagged items. Look for untagged resources. Check for orphaned EC2 instances, EBS volumes, or elastic IPs. Review NAT Gateway data transfer. Check if a data pipeline or CI/CD job ran excessively.
  2. Q: How would you reduce AWS costs by 30% without impacting production?

    • A: (1) Right-size instances using Compute Optimizer (10-20% savings), (2) Purchase Savings Plans for stable workloads (30-40%), (3) Use Spot instances for CI/CD and batch (60-90%), (4) Shut down dev/staging at night (65%), (5) S3 lifecycle policies for cold data, (6) Delete unused EBS snapshots and unattached volumes.

Exam Tip

  1. Consolidated Billing: Combines usage across accounts for volume discounts
  2. SCPs: Use to set permission boundaries, not grant permissions
  3. Reserved Instances: Best for steady-state workloads with 1-3 year commitment
  4. Savings Plans: More flexible than RIs, apply across EC2, Lambda, Fargate
  5. Spot Instances: Up to 90% discount, but can be interrupted
  6. Cost Allocation Tags: Must be activated to appear in billing reports
  7. Budget Actions: Can automatically restrict resources when budget exceeded

Chapter 3: AWS Identity and Access Management (IAM)


Last Updated: March 2026

Last Updated: February 2026