Hands-On Lab918 words

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), and organizations:* (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:

  1. Deploy AWS resources and apply metadata using Resource Tags.
  2. Activate Cost Allocation Tags to track usage on a granular level.
  3. Configure an AWS Budget to receive alerts when spending exceeds a predefined threshold.
  4. 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:

Loading Diagram...

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).

bash
# 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
  1. Navigate to S3 > Create bucket.
  2. Enter the bucket name: brainybee-billing-lab-<YOUR_ACCOUNT_ID>.
  3. Scroll down to the Tags section.
  4. Click Add tag.
  5. Key: Environment, Value: Lab.
  6. 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.

bash
# Activate the "Environment" tag for Cost Allocation aws ce update-cost-allocation-tags-status \ --tag-key "Environment" \ --tag-status Active
▶💻 Console Alternative
  1. Navigate to the Billing and Cost Management console.
  2. In the left navigation pane, choose Cost allocation tags.
  3. Under User-defined cost allocation tags, search for Environment.
  4. 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:

bash
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" } EOF

Next, apply the budget using the AWS CLI:

bash
# 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
  1. Navigate to Billing > Budgets.
  2. Click Create budget.
  3. Select Use a template (simplified) and choose Zero spend budget.
  4. Enter your email address in the recipient list.
  5. Click Create budget.

Here is how the Budget Evaluation Workflow operates behind the scenes:

Loading Diagram...

Step 4: Explore AWS Cost Explorer

Cost Explorer is highly visual and best utilized via the AWS Management Console.

  1. Navigate to the Billing and Cost Management console.
  2. Click on Cost Explorer in the left sidebar.
  3. If this is your first time, click Enable Cost Explorer (data will populate within 24 hours).
  4. In the main view, adjust the filter parameters:
    • Date Range: Last 3 Months
    • Group by: Service
  5. Optional: Once your tag activates (after 24 hours), you can filter the view by Tag > Environment > Lab to see exactly how much your S3 bucket costs.

Checkpoints

Verify that your resources have been deployed successfully:

1. Verify S3 Bucket Tags:

bash
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:

bash
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:

bash
# 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.json

Troubleshooting

Common Error / IssueProbable CauseFix / Solution
AccessDeniedException on Billing commandsIAM 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 ExplorerCost Allocation Tags have a delay.Wait up to 24 hours after activating the tag in the Billing console.
InvalidParameterException on S3 BucketBucket name is not globally unique.Ensure you replaced <YOUR_ACCOUNT_ID> with your actual, unique 12-digit AWS account ID.
Budget notifications not arrivingEmail address unverified or wrong threshold.Check the spam folder or verify you set the threshold to 100 (percent) of $0.01.

Ready to study AWS Certified Cloud Practitioner (CLF-C02)?

Practice tests, flashcards, and all study notes — free, no sign-up needed.

Start Studying — Free