Hands-On Lab: AWS Billing, Budgets, and Cost Management
Understand resources for billing, budget, and cost management
Hands-On Lab: AWS Billing, Budgets, and Cost Management
Welcome to this guided lab on AWS Cost Management! As an AWS Certified Cloud Practitioner, ensuring that your cloud infrastructure is cost-effective is just as critical as ensuring it is secure and highly available. In this lab, you will deploy a tagged resource, activate cost allocation tags, create a billing budget to prevent unexpected charges, and explore the AWS Cost Explorer.
Prerequisites
Before you begin, ensure you have the following:
- AWS Account: Administrative or Root access is highly recommended, as Billing features are restricted by default.
- CLI Tools: AWS CLI (
aws) installed and configured (aws configure). - IAM Permissions: Your user must have permissions for
s3:*,budgets:*,ce:*(Cost Explorer), andorganizations:*(if using consolidated billing).
[!IMPORTANT] By default, IAM users do not have access to the Billing Console. The root account user must enable IAM access to the Billing and Cost Management console in the Account Settings.
Learning Objectives
By the end of this lab, you will be able to:
- Deploy AWS resources and apply metadata using Resource Tags.
- Activate Cost Allocation Tags to track usage on a granular level.
- Configure an AWS Budget to receive alerts when spending exceeds a predefined threshold.
- Navigate AWS Cost Explorer to visualize and analyze historical cloud costs.
Architecture Overview
The following flowchart illustrates how resources, tags, and billing services interact in AWS:
Step-by-Step Instructions
Step 1: Create a Tagged Resource
To see how billing tracking works, we first need a resource to track. We will create an Amazon S3 bucket and assign it a specific tag (Environment: Lab).
# Replace <YOUR_ACCOUNT_ID> with a random string or your actual account ID to ensure global uniqueness
aws s3api create-bucket \
--bucket brainybee-billing-lab-<YOUR_ACCOUNT_ID> \
--region us-east-1
# Apply a resource tag to the bucket
aws s3api put-bucket-tagging \
--bucket brainybee-billing-lab-<YOUR_ACCOUNT_ID> \
--tagging '{"TagSet": [{"Key": "Environment", "Value": "Lab"}]}'▶💻 Console Alternative
- Navigate to S3 > Create bucket.
- Enter the bucket name:
brainybee-billing-lab-<YOUR_ACCOUNT_ID>. - Scroll down to the Tags section.
- Click Add tag.
- Key:
Environment, Value:Lab. - Click Create bucket.
📸 Screenshot: S3 Bucket creation screen with the Tags section highlighted.
[!TIP] Resource tags help administrators quickly identify the purpose and owner of a running resource, but they do not automatically appear in billing reports until you explicitly activate them as Cost Allocation Tags.
Step 2: Activate Cost Allocation Tags
To filter our billing dashboard by the Environment tag we just created, we must activate it in the Billing and Cost Management console.
# Activate the "Environment" tag for Cost Allocation
aws ce update-cost-allocation-tags-status \
--tag-key "Environment" \
--tag-status Active▶💻 Console Alternative
- Navigate to the Billing and Cost Management console.
- In the left navigation pane, choose Cost allocation tags.
- Under User-defined cost allocation tags, search for
Environment. - Select the tag and click Activate.
📸 Screenshot: Billing console showing the "Environment" tag status changing from Inactive to Active.
[!NOTE] It can take up to 24 hours for newly activated tags to appear in the AWS Cost Explorer.
Step 3: Create a Zero-Spend AWS Budget
AWS Budgets allows you to set custom thresholds and receive alerts. We will create a "Zero-Spend" budget that emails you if your AWS account incurs any charges > $0.01.
First, create a JSON file named budget.json:
cat <<EOF > budget.json
{
"BudgetLimit": {
"Amount": "0.01",
"Unit": "USD"
},
"BudgetName": "LabZeroSpendBudget",
"BudgetType": "COST",
"CostFilters": {},
"CostTypes": {
"IncludeEmail": true,
"IncludeTax": true,
"IncludeSubscription": true,
"UseBlended": false,
"IncludeRefund": false,
"IncludeCredit": false,
"IncludeUpfront": true,
"IncludeRecurring": true,
"IncludeOtherSubscription": true,
"IncludeSupport": true,
"IncludeDiscount": true,
"UseAmortized": false
},
"TimeUnit": "MONTHLY"
}
EOFNext, apply the budget using the AWS CLI:
# Replace <YOUR_ACCOUNT_ID> with your 12-digit AWS Account ID
aws budgets create-budget \
--account-id <YOUR_ACCOUNT_ID> \
--budget file://budget.json \
--notifications-with-subscribers Notification={"NotificationType":"ACTUAL","ComparisonOperator":"GREATER_THAN","Threshold":100},Subscribers=[{"SubscriptionType":"EMAIL","Address":"your-email@example.com"}]▶💻 Console Alternative
- Navigate to Billing > Budgets.
- Click Create budget.
- Select Use a template (simplified) and choose Zero spend budget.
- Enter your email address in the recipient list.
- Click Create budget.
Here is how the Budget Evaluation Workflow operates behind the scenes:
Step 4: Explore AWS Cost Explorer
Cost Explorer is highly visual and best utilized via the AWS Management Console.
- Navigate to the Billing and Cost Management console.
- Click on Cost Explorer in the left sidebar.
- If this is your first time, click Enable Cost Explorer (data will populate within 24 hours).
- In the main view, adjust the filter parameters:
- Date Range: Last 3 Months
- Group by: Service
- Optional: Once your tag activates (after 24 hours), you can filter the view by
Tag > Environment > Labto see exactly how much your S3 bucket costs.
Checkpoints
Verify that your resources have been deployed successfully:
1. Verify S3 Bucket Tags:
aws s3api get-bucket-tagging --bucket brainybee-billing-lab-<YOUR_ACCOUNT_ID>Expected Output: JSON containing the Environment: Lab key-value pair.
2. Verify Budget Creation:
aws budgets describe-budgets --account-id <YOUR_ACCOUNT_ID>Expected Output: JSON detailing the LabZeroSpendBudget with a $0.01 limit.
Clean-Up / Teardown
[!WARNING] Remember to run the teardown commands to avoid ongoing charges. While S3 storage costs are extremely low for empty buckets, leaving unneeded resources active is a bad cloud practice.
Execute the following commands to tear down the lab resources:
# 1. Delete the S3 Bucket (force deletes all objects inside)
aws s3 rb s3://brainybee-billing-lab-<YOUR_ACCOUNT_ID> --force
# 2. Delete the AWS Budget
aws budgets delete-budget \
--account-id <YOUR_ACCOUNT_ID> \
--budget-name "LabZeroSpendBudget"
# 3. Clean up the local JSON file
rm budget.jsonTroubleshooting
| Common Error / Issue | Probable Cause | Fix / Solution |
|---|---|---|
AccessDeniedException on Billing commands | IAM user lacks Billing permissions. | Log in as the Root user, go to Account Settings, and enable "IAM User and Role Access to Billing Information". |
| Tags are not showing up in Cost Explorer | Cost Allocation Tags have a delay. | Wait up to 24 hours after activating the tag in the Billing console. |
InvalidParameterException on S3 Bucket | Bucket name is not globally unique. | Ensure you replaced <YOUR_ACCOUNT_ID> with your actual, unique 12-digit AWS account ID. |
| Budget notifications not arriving | Email address unverified or wrong threshold. | Check the spam folder or verify you set the threshold to 100 (percent) of $0.01. |