This repository contains reference code for the "GenAI-Powered Cost Analysis" demo presented at AWS Summit Bangkok 2025. This chatbot application demonstrates how generative AI can be leveraged to analyze AWS cost data using Amazon Bedrock.
This repository is provided for reference purposes only.
- This code is a simplified version of the demo application shown at the event.
- It is not intended for production use without significant modification and proper security review.
- Many backend components were manually created through the AWS Console and are not included in this codebase.
- Streamlit Frontend: Implemented in
frontend/app.py - Application Load Balancer: Defined in
infra/ecs.yaml - Web Application Firewall (WAF): Defined in
infra/ecs.yaml
- Lambda Functions:
- Lambda Augment Prompt: Implemented in
backend/functions/format-agent-prompt/ - Lambda Query CUR Action Group: Implemented in
backend/functions/analyze-cur/
- Lambda Augment Prompt: Implemented in
- Helper Layer: Implemented in
backend/functions/layers/helper-layer/
- Prompt Template KB Query Template: From
from-aws/bedrock/prompt-management/cur-library-kb-template.txt - Prompt Template Agent Query Template: From
from-aws/bedrock/prompt-management/agent-template.xml
-
Amazon Bedrock Resources:
- Bedrock Flow (created via AWS Console)
- Bedrock Foundation Model (AWS managed)
- Bedrock Knowledge Base (created via AWS Console)
- Bedrock Guardrails (created via AWS Console)
- Bedrock Agent (created via AWS Console)
-
Storage Resources:
- S3 Bucket for Athena Query Results
- S3 Bucket for Cost and Usage Report (CUR) Data
- S3 Bucket for Knowledge Base Documents
- Glue Data Catalog
-
Query & Analysis Components:
- Amazon Athena service
- AWS Cost and Usage Reports configuration
The application utilizes:
- Amazon Bedrock: Powers the core conversational AI capabilities
- Bedrock Agent: Handles natural language queries about AWS costs
- Bedrock Knowledge Base: Contains information about cost patterns and query examples
- Bedrock Flow: Orchestrates the conversation flow and data preparation
- AWS Lambda: For serverless compute functions that:
- Analyze Cost and Usage Reports data via Athena
- Format and enhance agent prompts
- Amazon Athena: To query structured AWS cost data stored in S3
- Streamlit Frontend: Web UI for interacting with the cost analysis chatbot
backend/
├── functions/ # AWS Lambda function implementations
│ ├── analyze-cur/ # Function to analyze cost data through Athena
│ ├── format-agent-prompt/ # Function to format Bedrock agent prompts
│ └── layers/ # Shared code layers for Lambda functions
└── template.yaml # SAM template for Lambda resources
frontend/
├── app.py # Streamlit application for the web UI
├── dockerfile # Container definition for frontend deployment
├── requirements.txt # Python dependencies for the frontend
└── utils/ # Utility functions for the frontend
infra/
└── *.yaml # Infrastructure templates for deployment
This repository does not include:
-
Amazon Bedrock Resources: These were created manually through the AWS Console:
- Agent configuration and action groups
- Knowledge Base setup and documents
- Flow definitions
- Prompt templates
-
AWS IAM Roles and Permissions: Required permissions are referenced in the SAM template but not fully defined
-
AWS Cost and Usage Report Configuration: Details on setting up and formatting CUR data
To implement a similar solution, you would need:
- AWS Account with access to Amazon Bedrock
- Configured Cost and Usage Reports with data in S3
- Amazon Athena set up to query these reports
- Properly configured IAM roles and permissions
- Bedrock Agent, Knowledge Base, and Flow resources
The application requires several environment variables to be set:
ATHENA_CATALOG,ATHENA_DATABASE,ATHENA_WORKGROUP: Athena configurationBEDROCK_PROMPT_ID,BEDROCK_PROMPT_VERSION: Bedrock prompt template references
AWS_REGION: AWS region where resources are deployedBEDROCK_FLOW_ID,BEDROCK_FLOW_ALIAS_ID: References to the Bedrock FlowBEDROCK_AGENT_ID,BEDROCK_AGENT_ALIAS_ID: References to the Bedrock AgentSSM_PASSWORD_PARAM: Optional SSM parameter name for demo password
This project is licensed under the MIT License - see the LICENSE file for details.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
