Introduction
Managing cloud costs and understanding resource usage can be a daunting task, especially for organizations with complex AWS deployments. AWS Cost and Usage Reports (AWS CUR) provides valuable data insights, but interpreting and querying the raw data can be challenging. In this post, we explore a solution that uses generative artificial intelligence (AI) to generate a SQL query from a user’s question in natural language.
Managing Cloud Costs with Generative AI
The solution uses Amazon Bedrock, a fully managed service that offers a choice of high-performing foundation models (FMs) from leading AI companies like AI21 Labs, Anthropic, Cohere, Meta, Mistral AI, Stability AI, and Amazon through a single API, along with a broad set of capabilities to build generative AI applications with security, privacy, and responsible AI.
Challenges Addressed
The following challenges can hinder organizations from effectively analyzing their CUR data, leading to potential inefficiencies, overspending, and missed opportunities for cost-optimization. We aim to target and simplify them using generative AI with Amazon Bedrock.
- Complexity of SQL queries – Writing SQL queries to extract insights from CUR data can be complex, especially for non-technical users or those unfamiliar with the CUR data structure (unless you’re a seasoned database administrator)
- Data accessibility – To gain insights from structured data in databases, users need to get access to databases, which can be a potential threat to overall data protection
- User-friendliness – Traditional methods of analyzing CUR data often lack a user-friendly interface, making it challenging for non-technical users to take advantage of the valuable insights hidden within the data
Solution Overview
The solution that we discuss is a web application (chatbot) that allows you to ask questions related to your AWS costs and usage in natural language. The application generates SQL queries based on the user’s input, runs them against an Athena database containing CUR data, and presents the results in a user-friendly format. The solution combines the power of generative AI, SQL generation, database querying, and an intuitive web interface to provide a seamless experience for analyzing CUR data.
Solution Architecture
The data flow consists of the following steps:
- The CUR data is stored in Amazon S3.
- Athena is configured to access and query the CUR data stored in Amazon S3.
- The user interacts with the Streamlit web application and submits a natural language question related to AWS costs and usage.
- The Streamlit application sends the user’s input to Amazon Bedrock, and the LangChain application facilitates the overall orchestration.
- The LangChain code uses the BedrockChat class from LangChain to invoke the FM and interact with Amazon Bedrock to generate a SQL query based on the user’s input.
- The generated SQL query is run against the Athena database using the FM on Amazon Bedrock, which queries the CUR data stored in Amazon S3.
- The query results are returned to the LangChain application.
- LangChain sends the SQL query and query results back to the Streamlit application.
- The Streamlit application displays the SQL query and query results to the user in a formatted and user-friendly manner.
Prerequisites
To set up this solution, you should have the following prerequisites:
Configure the Solution
Complete the following steps to set up the solution:
- Create an Athena database and table to store your CUR data. Make sure the necessary permissions and configurations are in place for Athena to access the CUR data stored in Amazon S3.
- Set up your compute environment to call Amazon Bedrock APIs. Make sure you associate an IAM role with this environment that has IAM policies that grant access to Amazon Bedrock.
- When your instance is up and running, install the following libraries:
Clean Up
Unless you invoke Amazon Bedrock with this solution, you won’t incur charges for it. To avoid ongoing charges for Amazon S3 storage for saving the CUR reports, you can remove the CUR data and S3 bucket. If you set up the solution using Amazon EC2, make sure you stop or delete the instance when you’re done.
Benefits
This solution offers the following benefits:
- Simplified data analysis – You can analyze CUR data using natural language using generative AI, eliminating the need for advanced SQL knowledge
- Increased accessibility – The web-based interface makes it efficient for non-technical users to access and gain insights from CUR data without needing credentials for the database
- Time-saving – You can quickly get answers to your cost and usage questions without manually writing complex SQL queries
- Enhanced visibility – The solution provides visibility into AWS costs and usage, enabling better cost-optimization and resource management decisions
Conclusion
The AWS CUR chatbot solution uses Anthropic Claude on Amazon Bedrock to generate SQL queries, database querying, and a user-friendly web interface to simplify the analysis of CUR data. By allowing you to ask natural language questions, the solution removes barriers and empowers both technical and non-technical users to gain valuable insights into AWS costs and resource usage.
Frequently Asked Questions
Q1: What is the purpose of this solution?
This solution is designed to simplify the process of analyzing AWS Cost and Usage Reports (CUR) data using natural language and generative AI.
Q2: What are the benefits of this solution?
This solution offers several benefits, including simplified data analysis, increased accessibility, time-saving, and enhanced visibility into AWS costs and usage.
Q3: What is the prerequisite for setting up this solution?
You should have an Athena database and table to store your CUR data, and a compute environment to call Amazon Bedrock APIs.
Q4: How does the solution work?
The solution uses a web application (chatbot) that generates SQL queries based on the user’s input, runs them against an Athena database containing CUR data, and presents the results in a user-friendly format.
Q5: Can I customize this solution?
Yes, you can customize this solution by modifying the code and adapting it to your specific use case.