Streamlining AWS Cost Management: A Guide to Leveraging Amazon Q CLI and MCP
Introduction
Managing and optimizing AWS infrastructure costs is a critical challenge for organizations of all sizes. Traditional cost analysis approaches often involve complex spreadsheets, multiple tools, specialized knowledge, and time-consuming analysis, leading to delayed insights.
Revolutionizing Cost Analysis with Amazon Q CLI
Amazon Q Developer CLI, powered by the Model Context Protocol (MCP), offers a groundbreaking solution for AWS cost analysis, enabling teams to generate detailed estimates and recommendations in minutes.
Solution Overview
The Amazon Q Developer CLI is a command line interface that leverages generative AI capabilities, making sophisticated cost analysis accessible through natural language prompts.
Prerequisites and Environment Setup
Learn what you need to implement this solution, including AWS account requirements and detailed setup instructions for Amazon Q CLI and MCP servers.
Understanding MCP Server Tools
Explore the powerful tools provided by the AWS Cost Analysis MCP server and how they work together to generate accurate cost estimates in accordance with AWS best practices.
Testing and Configuration
Verify your setup’s functionality and customize your cost analysis experience with configuration options provided by the AWS Cost Analysis MCP server.
Creating AWS Cost Analysis Reports
Step-by-step guidance on crafting comprehensive AWS cost analysis reports through Amazon Q CLI with the AWS Cost Analysis MCP server.
Real-World Examples
Explore real-world architecture patterns and how to analyze their costs effectively using Amazon Q CLI, including examples for e-commerce and data analytics platforms.
Conclusion
Discover the advantages of using Amazon Q CLI and the AWS Cost Analysis MCP server for enhanced AWS cost management, and additional resources for advancing your understanding of cost optimization.
About the Authors
Learn more about the authors’ backgrounds and expertise in the field of AWS and cloud architecture.
Unlocking Cost Efficiency: Mastering AWS Infrastructure Costs with Amazon Q CLI and MCP
Managing and optimizing AWS infrastructure costs is a critical challenge for organizations of all sizes. Traditional cost analysis approaches can be cumbersome, often involving complex spreadsheets, multiple tools, specialized knowledge of AWS pricing, and time-consuming manual comparisons. Such methods often lead to delayed optimizations, which can hinder timely architectural decisions.
Enter Amazon Q Developer CLI and the Model Context Protocol (MCP). This powerful combination offers a revolutionary approach to AWS cost analysis. By harnessing generative AI through natural language prompts, teams can produce detailed cost estimates and optimization recommendations in mere minutes while ensuring accuracy with integrated AWS pricing data.
In this post, we will delve into how to harness Amazon Q CLI with the AWS Cost Analysis MCP server to perform sophisticated cost analysis aligned with AWS best practices. We’ll cover basic setup and advanced techniques, along with step-by-step examples.
Solution Overview
The Amazon Q Developer CLI is a command-line interface that integrates the generative AI capabilities of Amazon Q directly into your terminal. This tool allows developers to interact with Amazon Q using natural language prompts, making it an invaluable resource for various development tasks.
The Model Context Protocol (MCP) is an open standard developed by Anthropic that connects AI models to different data sources or tools. Its client-server architecture enables developers to expose their data through lightweight MCP servers while creating AI applications as MCP clients that connect to these servers.
Components of the MCP
- Host: Programs like Anthropic’s Claude Desktop or IDEs requiring data access through the MCP protocol.
- Client: One-to-one connections with servers maintained by protocol clients.
- Server: Lightweight applications that expose functionalities through the standardized MCP.
- Data Sources: Local data sources (like databases) or external systems accessible via APIs.
The AWS Cost Analysis MCP server empowers Amazon Q to generate detailed cost estimates and optimization recommendations using real-time AWS pricing data.
Prerequisites
Before diving into cost analysis, ensure you have an AWS account with appropriate permissions.
Set Up Your Environment
Follow these steps to set up your working environment with Amazon Q CLI and the AWS Cost Analysis MCP server.
Install Amazon Q Developer CLI
- Download and install Amazon Q Developer CLI. Refer to the documentation for installation instructions.
- Verify the installation by running:
q --versionExpected output:
Amazon Q Developer CLI version 1.x.x - Configure Amazon Q CLI with your AWS credentials:
q loginChoose the appropriate login method.
Set Up MCP Servers
- Install Panoc:
pip install pandoc - Install UV:
pip install uv - Install Python (version 3.10 or newer):
uv python install 3.10 - Add the MCP servers configuration to your
~/.aws/amazonq/mcp.jsonfile:{ "mcpServers": { "awslabs.cost-analysis-mcp-server": { "command": "uvx", "args": ["awslabs.cost-analysis-mcp-server"], "env": { "FASTMCP_LOG_LEVEL": "ERROR" }, "autoApprove": [], "disabled": false } } }
Understanding MCP Server Tools
The AWS Cost Analysis MCP server includes several powerful tools:
- get_pricing_from_web: Fetches pricing details from AWS pricing webpages.
- get_pricing_from_api: Retrieves pricing data from the AWS Price List API.
- generate_cost_report: Creates comprehensive cost analysis reports with breakdowns.
- analyze_cdk_project and analyze_terraform_project: Examine projects to identify AWS services and estimate costs.
- get_bedrock_patterns: Retrieves architecture patterns for Amazon Bedrock considering cost factors.
Test Your Setup
To ensure everything is properly configured, generate a simple cost analysis:
-
Start the Amazon Q CLI chat interface:
q chat -
In the chat, enter the following prompt:
"Please create a cost analysis for a simple web application with an Application Load Balancer, two t3.medium EC2 instances, and an RDS db.t3.medium MySQL database. Assume 730 hours of usage per month and moderate traffic of about 100 GB data transfer. Convert the estimation to PDF format." -
Trust the tool when prompted by entering
t.
If successful, you should receive a detailed cost analysis report.
Configuration Options
The AWS Cost Analysis MCP server allows several configuration options to enhance your cost analysis experience:
- Output Format: Choose from markdown, CSV, or PDF.
- Pricing Model: Specify on-demand, reserved instances, or savings plans.
- Assumptions and Exclusions: Customize these elements for tailored analysis.
- Detailed Cost Data: Input specific usage patterns for precise estimates.
Creating AWS Cost Analysis Reports
Using Amazon Q CLI and the AWS Cost Analysis MCP server, creating cost analysis reports is seamless:
- Amazon Q interprets your requirements.
- It retrieves pricing data.
- A detailed cost analysis report is generated followed by optimization recommendations.
Example 1: Analyze a Serverless Application
Prompt:
"Create a cost analysis for a serverless application using API Gateway, Lambda, and DynamoDB. Assume 1 million API calls per month, average Lambda execution time of 200ms with 512MB memory, and 10GB of DynamoDB storage."
Upon entering, you’ll receive a detailed cost breakdown and optimizations.
Example 2: Analyze Multi-Tier Architectures
Prompt:
"Create a cost analysis for a three-tier web application with a presentation tier (ALB and CloudFront), application tier (ECS with Fargate), and data tier (Aurora PostgreSQL)."
The result will feature costs for each tier and overall optimizations.
Example 3: Compare Deployment Options
Prompt:
"Compare costs for running a containerized application on ECS with EC2 vs. Fargate launch type. Assume 4 containers needing 1 vCPU and 2GB memory, running 24/7 for a month."
Receive a detailed breakdown, including recommendations for the most effective option.
Real-World Examples
E-commerce Platform
Prompt:
"Create a cost analysis for an e-commerce platform with microservices architecture serving moderate traffic levels."
Data Analytics Platform
Prompt:
"Create a cost analysis for a data analytics platform processing 500GB of new data daily."
Clean Up
To remove the AWS Cost Analysis MCP server from your configuration:
- Edit
~/.aws/amazonq/mcp.json. - Comment out or delete the “awslabs.cost-analysis-mcp-server” entry.
Conclusion
We’ve explored how to use Amazon Q CLI with the AWS Cost Analysis MCP server for detailed cost analyses employing accurate AWS pricing data. This method offers significant advantages:
- Time Efficiency: Generate complex analyses in minutes.
- Accuracy: Use the latest AWS pricing information.
- Comprehensive Insights: Include all relevant cost components.
- Actionable Recommendations: Receive specific cost optimizations.
- Iterative Process: Quickly compare scenarios through natural prompts.
- Validation: Cross-check estimates with official AWS pricing.
As you advance your expertise in AWS cost analysis, consider delving deeper into the Model Context Protocol (MCP) and utilizing the AWS Pricing Calculator for interactive modeling. Also, stay updated on AWS Well-Architected Framework guidelines for cost optimization and continually enhance your cost analysis practices.
About the Authors
Joel Asante: Solutions Architect at AWS focused on GovTech, passionate about data analytics and cloud architectures.
Dunieski Otano: Solutions Architect at AWS dedicated to security and serverless solutions, with a strong industry presence.
Varun Jasti: Solutions Architect at AWS working on AI solutions to meet compliance standards, with a robust background in computer science.