AWS Solutions Architect Project (Cost Optimization Pillar) – Automated Cost Management – Part 1

As the good AWS architecture has to be efficient in terms of operational cost, in this project we’ll simulate on how to build a workflow to detect unused resources, recommend cleanup actions, and remove them safely with proper governance. We’ll start by deploying a wasteful AWS environment built via CloudFormation template and fix the cost leaking that caused by it.

To ensure this project run properly, we need to allow the created resources to at least running for about 1-2 hours so AWS CostExplorer and AWS Budgets has enough time to collect usage and cost metrics and AWS Trusted Advisor will be able to generate recommendations too

Below is the architecture diagram for this project:

Below is the explanation of above diagram:

  1. CloudFormation deploys monitoring, cost, and automation setup
  2. CloudWatch gathers usage metrics
  3. Cost Explorer identifies unused resources
  4. Systems Manager receives findings and prepares cleanup actions
  5. SNS sends cleanup notifications
  6. IAM grants System Manager permissions to perform the act
  7. System Manager executes cleanup on EC2, S3, and Elastic IPs

Step 1: Create The Wasteful Resources via CloudFormation

In this step, we will intentionally create the resources to simulate the real-world resources created under an AWS account. The purpose is to control the issue ourselves while keep the common real-world scenario on what to look for in such inefficient AS resources.

  • Go to CloudFormation console, click Create Stack
  • Prepare template: Choose an existing template
  • Download the following CloudFormation template from here
  • Choose Upload a template file and select the wasteful-infra-template.yaml file
  • Click Next, and enter CostManager-for-Wasteful-Infra to adhere with best practice by indicating the project and purpose

Step 2: Configure Stack Parameters

We need to tell CloudFormation where to deploy this resource by selecting the subnet

  • VPC ID: The location where resources will be created. Let’s use the default VPC one here
  • SubnetID: public subnet that proides internet access for EC2 instances
  • SubnetID2: second public subnet which has to be in a different availability zone for load balancer requirement

Get the above values by visiting VPC console and select Your VPCs. Click a VPC and find VPC ID and subnets under Resource Map tab

  • Continue to configure stack options, review it, and click Submit
  • Wait until all the status of resource deployment as CREATE_COMPLETE

Step 3: Check the Created Resources

By far, below is the successfully created resource by the CloudFormation stack

  1. Two oversized EC2 instances (t3.small) – Over-provisioned compute that could use t3.micro, still wasting ~$15/month each
  2. Three unattached EBS volumes (50GB, 50GB, 100GB) – Pure storage waste costing ~$20/month total
  3. Two unattached Elastic IP addresses – Common oversight generating $7.20/month when unused
  4. An S3 bucket for static website hosting using Standard storage without lifecycle policies – Inefficient storage management
  5. Overly permissive security groups – Opens HTTP (port 80) and SSH (port 22) to all IPs (0.0.0.0/0)

Notice that all resources were tagged with Project: CostManager

Step 4: Configure S3 Manually

As some AWS resources, such as S3, cannot be fully configured via CloudFormation, we need to manually configure its bucket policies and static website hosting

Let’s configure S3 bucket policy first

  • Go to S3 console, select Buckets, select costmanager-frontend-<account_id>-<region>
  • Click the Permissions tab
  • Scroll down to Bucket Policy section, click Edit, and paste below policy:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::costmanager-frontend-505679505148-us-east-1/*"
        }
    ]
}
  • Replace <account-id> and <region> based on the actual values on our S3 bucket arn
  • Click Save Changes

This policy makes bucket contents publicly readable. In production, we would use CloudFront and more restrictive policies.

Step 5: Upload Website Content

We are going to create a static landing page on S3 bucket for this demonstration

  • Download this file: index.html
  • Upload to S3 bucket. Go to Objects tab, click Upload -> Add files and select index.html

Step 6: Validate and Review Generated Resources and Costs

Go to EC2 console and check the following:

  • Instances: Confirm one t3.small and one t3.medium, instances are running in different AZs
  • Volumes: Verify three unattached volumes (50GB, 50GB, 100GB) – these should show as “available” not “in-use”. See the volume state column, “Available” means unattached = wasteful spending
  • Elastic IPs: Verify two unattached Elastic IP addresses (should show as “not associated”)

Next, go to S3 Console to check the following:

  • Buckets: Verify the CostManager frontend bucket exists
  • Management tab: Confirm no lifecycle rules are configured
  • Properties tab: Verify website hosting is enabled with index.html as index document
  • Security Groups:
    • EC2 Console → Security Groups: Find “SimpleSecurityGroup”
    • Inbound rules: Confirm overly broad access (0.0.0.0/0) for ports 22 and 80

The above resources will generate estimated costs like the following:

  • EC2 instances: ~$0.0208/hour each (t3.small) = ~$30/month for both
  • EBS volumes: ~$0.10/GB/month for unattached storage = ~$20/month total
  • Elastic IPs: $0.005/hour each when unattached = ~$7.20/month total
  • S3 storage: Standard pricing without lifecycle optimization (minimal for empty bucket)

Total estimated monthly cost: $30-40


Summary

After the deployment, we should have the following:

  • A functioning S3 bucket configured for static website hosting Multiple cost-inefficient resources actively generating charges Clear examples of common cloud waste patterns:
  • Oversized compute instances
  • Unattached storage resources
  • Unattached network resources (Elastic IPs)
  • Poor security practices (overly broad security groups)
  • Lack of storage lifecycle management
  • Tagged resources for easy identification and cleanup Baseline data for cost optimization exercises

In the next step, after letting the resource running for at least 1-2 hours, we will do the following:

  • Analyze costs using AWS Cost Explorer Identify waste using AWS Trusted Advisor Set up cost monitoring and alerts Practice cost optimization techniques:
  • Rightsizing EC2 instances (t3.small → t3.micro)
  • Cleaning up unattached resources
  • Implementing S3 lifecycle policies
  • Securing security groups
  • Clean up resources to stop charges