AWS Builder Center
Weekend Showcase Challenge: AWS CostGuard

Weekend Showcase Challenge: AWS CostGuard

AWS CostGuard is a serverless AWS cost monitoring and reporting system that automatically retrieves daily and month-to-date AWS spending, analyzes service-wise costs, generates reports, and delivers them through email. Built with AWS Lambda, Cost Explorer, EventBridge, SES, IAM, and Google Sheets integration.

I'm a Computer Science student passionate in building secure, scalable and reliable cloud solutions

AWS CostGuard: Automated AWS Cost Monitoring and Reporting

#application

Introduction

Cloud computing makes it incredibly easy to create and scale infrastructure, but it can also make it difficult to keep track of spending. When working with multiple AWS services, manually checking AWS Cost Explorer every day can become repetitive, especially when I want to quickly understand how much I spent and which services are responsible for the cost.
This led me to build AWS CostGuard, a serverless AWS cost monitoring and reporting system designed to make AWS cost tracking simpler and more automated.
The idea behind CostGuard is simple: instead of manually checking AWS costs every day, the system retrieves the information programmatically, analyzes it, generates a report, and delivers the results automatically.

The Problem

While learning and building projects on AWS, I noticed that cloud costs can change depending on the resources being used. A running EC2 instance, database, storage, API calls, or other services can contribute to the overall AWS bill.
I wanted a solution that could answer a few important questions automatically:
  • How much did I spend today?
  • How much did I spend yesterday?
  • What was my spending the day before yesterday?
  • How much have I spent so far this month?
  • Which AWS services are costing the most?
  • Can I receive this information without manually opening the AWS console?
These questions became the foundation of AWS CostGuard.

What CostGuard Does

CostGuard uses AWS Cost Explorer to retrieve AWS cost information and processes that information using a Python-based AWS Lambda function.
The system calculates:
  • Today's estimated cost
  • Yesterday's cost
  • Day-before-yesterday's cost
  • Month-to-date cost
  • Service-wise AWS spending
  • Services sorted from highest to lowest cost
The system can also generate a CSV report containing the cost information.
The goal is to turn raw AWS billing information into a report that is easier to understand and use.
A typical report can provide information such as:
AWS COSTGUARD REPORT
Today's Cost: $X.XX
Yesterday's Cost: $X.XX
Day Before Yesterday: $X.XX
Month-to-Date Cost: $XX.XX
SERVICE-WISE COST
EC2 $XX.XX
RDS $X.XX
S3 $X.XX
Lambda $X.XX
Other $X.XX
The actual values are retrieved directly from the AWS account.

Architecture

I designed CostGuard using a serverless architecture so that I would not need to maintain a dedicated server for the monitoring system.
The overall workflow is:
EventBridge Scheduler
|
v
AWS Lambda
|
v
AWS Cost Explorer
|
v
Cost Analysis
|
+-----+------+
| |
v v
CSV Report Amazon SES
|
v
Email Report
The Lambda function acts as the main processing layer. It communicates with AWS Cost Explorer through the AWS SDK for Python, also known as Boto3.
The processed results can then be sent through Amazon SES and stored in Google Sheets for historical tracking.

AWS Services Used

AWS Lambda

AWS Lambda is the core processing component of CostGuard. It executes the Python code responsible for retrieving AWS cost information, calculating different time periods, processing service-wise costs, and generating the report.
Using Lambda means I do not need to maintain a dedicated server just to run the cost-monitoring application.

AWS Cost Explorer

AWS Cost Explorer provides the cost and usage information used by CostGuard.
Instead of manually opening Cost Explorer and checking different date ranges, CostGuard accesses the required information programmatically through the AWS API.

Amazon EventBridge Scheduler

EventBridge Scheduler can automatically trigger the Lambda function at a scheduled time.
This makes it possible to run CostGuard automatically and receive regular cost reports without manually invoking the Lambda function.

Amazon SES

Amazon Simple Email Service is used to send the generated cost report through email.
This makes the results accessible without requiring the user to open the AWS console every time.

AWS IAM

IAM is used to control permissions between the AWS services.
This was an important part of the project because the Lambda function should have only the permissions required to perform its tasks rather than unnecessary access to other AWS resources.

Google Sheets

I also explored Google Sheets integration so that cost information could be maintained historically.
Instead of replacing previous results, new cost information can be appended, allowing the spending history to be reviewed over time.

How I Built It

I started by creating a Lambda function capable of communicating with AWS Cost Explorer using Boto3.
The first step was retrieving cost information for a specific date range. I then expanded the function to calculate multiple periods, including today's cost, yesterday's cost, the previous day's cost, and the month-to-date total.
After the basic calculations were working, I added service-wise cost analysis and sorted the services according to their spending.
The next step was generating a CSV report so that the results could be stored and shared easily.
Finally, I integrated Amazon SES to send the report through email and worked on Google Sheets integration for maintaining historical cost information.
Building the project step by step helped me understand how individual AWS services can be combined to create a useful application.

Challenges I Faced

One of the biggest challenges was correctly handling date ranges with AWS Cost Explorer.
During development, I encountered errors related to invalid start and end dates. This required me to understand how AWS Cost Explorer handles time periods and how to correctly calculate the required date ranges.
I also encountered a Lambda timeout during testing. This taught me that even a relatively small serverless application needs to consider execution time and the number of external API operations being performed.
Another challenge was configuring IAM permissions correctly.
The Lambda function needed access to the required AWS APIs, but giving excessive permissions would create an unnecessary security risk. This helped me understand the importance of least-privilege access when designing AWS applications.
These challenges taught me that building a cloud application is not only about making the code work. Permissions, API behavior, execution time, error handling, and architecture all matter.

What I Learned Across the Summer

Building CostGuard helped me move from learning AWS services individually to understanding how multiple AWS services can work together to solve a real-world problem.
I gained practical experience with:
  • AWS Lambda
  • AWS Cost Explorer
  • Boto3
  • IAM
  • Amazon SES
  • EventBridge Scheduler
  • CSV report generation
  • Google Sheets integration
  • Serverless architecture
  • AWS cost management
One of my biggest takeaways was that a useful cloud solution does not necessarily need a large number of services.
A small number of well-connected managed services can solve a meaningful problem when the architecture is designed properly.
I also learned that cloud cost management should be considered during development rather than only after receiving an AWS bill.

What's Next for CostGuard?

CostGuard is currently a foundation that I want to continue improving.
One of the next features I want to add is automated cost threshold alerting.
For example, CostGuard could compare today's spending with previous spending and send an alert when there is an unusual increase.
The future workflow could look like:
AWS Cost Data
|
v
CostGuard Lambda
|
v
Cost Analysis
|
+--+--+
| |
Normal Unusual
|
v
Cost Alert
I also want to add historical dashboards, better cost visualization, configurable spending thresholds, and support for monitoring multiple AWS accounts.
The long-term goal is to evolve CostGuard from a simple reporting system into a more proactive cloud cost monitoring and FinOps solution.

Final Thoughts

AWS CostGuard started with a simple question:
What if I didn't have to manually check my AWS costs every day?
That question turned into a practical serverless project connecting AWS Lambda, Cost Explorer, EventBridge, SES, IAM, and reporting components.
What I enjoyed most about this project was that it was not simply about deploying an application. I had to think about how services communicate, how permissions should be configured, how APIs behave, how failures should be handled, and how cloud usage translates into cost.
This project gave me a much better understanding of AWS and cloud architecture and showed me how serverless services can be combined to solve a real-world problem.
I am excited to continue improving CostGuard and take it from an automated cost report generator toward a more proactive cloud cost management platform.

Project Links

Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article