Hands-On Lab950 words

Lab: Implementing AWS Cost Optimization and Governance

Determine a cost optimization strategy to meet solution goals and objectives

Lab: Implementing AWS Cost Optimization and Governance

This lab guides you through the practical application of cost optimization strategies as defined in the AWS Certified Solutions Architect - Professional (SAP-C02) curriculum. You will focus on visibility, governance, and rightsizing tools.

Prerequisites

  • AWS Account: An active AWS account is required.
  • IAM Permissions: You must have AdministratorAccess or equivalent permissions to manage Budgets, Compute Optimizer, and Tagging.
  • AWS CLI: Installed and configured on your local machine with <YOUR_REGION> (e.g., us-east-1).
  • Basic Knowledge: Familiarity with EC2, S3, and the AWS Management Console.

Learning Objectives

By the end of this lab, you will be able to:

  1. Create and manage AWS Budgets to track spending against targets.
  2. Enable and interpret AWS Compute Optimizer findings for rightsizing.
  3. Implement a tagging strategy using the AWS CLI for cost allocation.
  4. Utilize S3 Storage Lens to identify cost-saving opportunities in storage.

Architecture Overview

In this lab, you will interact with various AWS management services that monitor and govern your resource consumption without necessarily deploying heavy infrastructure.

Loading Diagram...

Step-by-Step Instructions

Step 1: Create a Monthly Cost Budget

Setting up a budget is the first step in the FinOps "Visibility" phase. We will create a budget that alerts you when 80% of a $10 monthly limit is reached.

CLI Instructions:

  1. Create a file named budget.json locally:
json
{ "BudgetName": "Monthly_Lab_Budget", "BudgetLimit": { "Amount": "10.0", "Unit": "USD" }, "TimeUnit": "MONTHLY", "BudgetType": "COST" }
  1. Execute the following command:
bash
aws budgets create-budget --account-id <YOUR_ACCOUNT_ID> --budget file://budget.json --notifications-with-subscribers '[]'
Console alternative
  1. Navigate to the AWS Billing and Cost Management console.
  2. In the left navigation pane, choose Budgets.
  3. Click Create budget.
  4. Choose Cost budget (Recommended) and click Next.
  5. Set Budget name to Monthly_Lab_Budget and Amount to $10.
  6. Click Next to configure alerts and finish.

[!TIP] In a production environment, always link your budget to an SNS topic for automated incident response (e.g., triggering a Lambda to stop dev instances).

Step 2: Enable AWS Compute Optimizer

Compute Optimizer uses machine learning to recommend rightsizing. It requires at least 30 hours of resource metrics to provide deep insights, but we will ensure it is enabled.

CLI Instructions:

bash
aws compute-optimizer update-enrollment-status --status Active
Console alternative
  1. Search for Compute Optimizer in the AWS Console.
  2. If not already enabled, click Get started.
  3. Select Opt-in for the current account.

Step 3: Implement Tagging for Cost Allocation

Tagging allows you to attribute costs to specific departments or projects. We will tag an existing resource (or a placeholder) with a CostCenter tag.

CLI Instructions:

  1. Identify a resource ARN (e.g., an S3 bucket or EC2 instance).
  2. Run the following:
bash
aws resourcegroupstaggingapi tag-resources --resource-arn-list <YOUR_RESOURCE_ARN> --tags CostCenter=Research-101

Step 4: Configure S3 Storage Lens

S3 Storage Lens provides organization-wide visibility into object-storage usage and activity trends.

Console Instructions:

  1. Navigate to S3 > Storage Lens > Dashboards.
  2. Observe the default-account-dashboard (created by AWS automatically).
  3. Click on the dashboard and look for the Cost optimization tab to find incomplete multi-part uploads or expired object versions.

Checkpoints

Verification TaskCommand / ActionExpected Result
Verify Budgetaws budgets describe-budgets --account-id <YOUR_ACCOUNT_ID>JSON output containing Monthly_Lab_Budget
Check Taggingaws resourcegroupstaggingapi get-resources --tag-filters Key=CostCenter,Values=Research-101The ARN of your tagged resource appears
Check Opt-inaws compute-optimizer get-enrollment-statusStatus should be Active

Concept Review

Understanding the trade-off between cost and performance is central to the SAP-C02 exam. The following diagram illustrates the "Optimization Zone."

\begin{tikzpicture}[scale=0.8] % Axes \draw[->, thick] (0,0) -- (6,0) node[right] {Performance}; \draw[->, thick] (0,0) -- (0,6) node[above] {Cost};

code
% Curves \draw[blue, thick] (0.5,5.5) to [out=-80, in=170] (5.5,0.5); \node[blue] at (4,3) {Underutilized}; \node[red] at (1,1) {Optimized Zone}; % Highlight point \filldraw[red] (1.5,1.5) circle (2pt); \draw[dashed] (1.5,0) -- (1.5,1.5) -- (0,1.5); % Annotations \draw [decorate,decoration={brace,amplitude=5pt,mirror,raise=4pt},yshift=0pt] (0.5,5.5) -- (2.5,2.5) node [black,midway,xshift=1.2cm, yshift=0.5cm] {Waste};

\end{tikzpicture}

Comparison of Purchasing Models

ModelCommitmentDiscountBest Use Case
On-DemandNone0%Spiky, unpredictable workloads
Spot InstancesNone (Interruptible)Up to 90%Batch processing, stateless apps
Savings Plans1 or 3 yearsUp to 72%Consistent compute usage (EC2, Fargate, Lambda)

Troubleshooting

ProblemPotential CauseSolution
AccessDenied when creating budgetMissing IAM budgets:ModifyBudgetUpdate IAM policy to include Budget permissions.
No data in Compute OptimizerNew account or no active resourcesEnsure resources (EC2/EBS) have been running for at least 30 hours.
CLI command not foundAWS CLI not installedInstall the v2 AWS CLI and run aws configure.

Challenge

Goal: Create an AWS Budget Action.

  1. Modify your budget to include an "Action" that attaches an IAM policy to a specific user to restrict resource creation if the budget is exceeded by 100%.
  2. Hint: Use the aws budgets create-budget-action command.

Cost Estimate

  • AWS Budgets: First 2 action-enabled budgets are free; otherwise, $0.02/day per budget.
  • Compute Optimizer: Free for standard EC2/EBS/Lambda metrics.
  • S3 Storage Lens: Free tier includes 28 metrics; Advanced metrics cost $0.20 per million objects monitored.
  • Total Estimated Lab Cost: $0.00 (within Free Tier).

Clean-Up / Teardown

[!WARNING] Failure to delete budgets and remove tags can lead to minor ongoing costs if you exceed free limits.

  1. Delete the Budget:
bash
aws budgets delete-budget --account-id <YOUR_ACCOUNT_ID> --budget-name Monthly_Lab_Budget
  1. Remove the Tag:
bash
aws resourcegroupstaggingapi untag-resources --resource-arn-list <YOUR_RESOURCE_ARN> --tag-keys CostCenter
  1. Opt-out of Compute Optimizer (Optional):
bash
aws compute-optimizer update-enrollment-status --status Inactive

Ready to study AWS Certified Solutions Architect - Professional (SAP-C02)?

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

Start Studying — Free