Skip to content

Account_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 | |
| +----------------------------------------------+ |
| |
+------------------------------------------------------------------+

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: February 2026