AWS Cloud Financial Management

Cost Analysis for Amazon CloudWatch Using Amazon Q CLI and MCP servers

Managing cloud monitoring resources can become complex as your infrastructure grows. If you are responsible for Amazon CloudWatch across multiple environments, you have likely experienced the challenge of tracking and optimizing hundreds of log groups, metrics, and alarms. Traditionally, cost analysis meant manually exploring multiple insights, filtering through various dimensions, and switching between AWS Cost Explorer and Amazon CloudWatch to identify cost drivers. This approach is time-consuming and can lead to missed optimization opportunities.

Amazon Q Developer CLI (Amazon Q CLI) with the Model Context Protocol (MCP) for Billing and Cost Management and Amazon CloudWatch enables teams to quickly generate detailed cost analyses, perform deep dives into usage patterns, and receive optimization recommendations through a streamlined interface.

Amazon Q CLI with MCP servers simplifies CloudWatch cost analysis. Using natural language prompts, you can identify cost drivers and receive optimization recommendations for your resources. This streamlined approach minimizes manual exploration, enhances financial control, and improves cloud efficiency.

The steps below allow you to connect Amazon Q CLI to AWS Cost Explorer and CloudWatch, delivering real-time data analysis through conversational queries. By transforming complex cost analysis into simple dialogue, you will be empowered to achieve immediate insights and optimize cloud spending with minimal effort.

Solution Overview

  1. Provide a natural language query
  2. Amazon Q CLI processes your input
  3. MCP client selects the appropriate MCP servers for analysis
  4. MCP servers interact with AWS CloudWatch and AWS Cost Explorer using your AWS credentials
  5. Receive actionable insights

Figure 1: Amazon Q Developer CLI MCP server Workflow

Prerequisites

Set up MCP servers in Amazon Q Developer CLI

Different MCP hosts, such as Amazon Q Developer CLI, Claude Desktop, Kiro, Visual Studio Code and other MCP compatible tools integrate with Billing and Cost Management, and Amazon CloudWatch MCP Servers. For this solution we focus on Amazon Q Developer CLI example.

  • Create the MCP configuration file (mcp.json) in the Amazon Q Developer CLI’s local directory (~/.aws/amazonq/)
  • Update your mcp.json file with AWS Billing and Cost Management MCP Server and CloudWatch MCP Server configurations

1. Login to Amazon Q and Initiating the MCP Server

Figure 2. Initiating the Amazon Q CLI with MCP server

2. Run the /tools command as shown in Figure 3 to check the MCP server status

Figure 3. Tools list in Amazon Q Developer CLI

By default, tools are in the per-request state (not trusted), requiring Amazon Q to ask for permission before using a tool. In the trusted state, Amazon Q can utilize tools automatically, enabling a streamlined workflow without confirmation for each usage. For more details on managing tool permissions and switching between trust states, refer to the documentation.

Cost Considerations

You can incur charges when the MCP makes calls to AWS service APIs. For current pricing information review the respective services API pricing, or you can ask the Billing Cost Management MCP server through natural language queries.

Using Natural Language for Cost Analysis

Below are multiple scenarios that showcase natural language queries for interacting with AWS services like CloudWatch and Cost Explorer. These examples were generated using the Amazon Q CLI in conjunction with the CloudWatch MCP Server and the Billing Cost Management MCP server.

Analyzing the AWS service cost

“What was the total cost incurred for AWS service during the last month?”

Figure 4. Analyzing the AWS service cost

Amazon CloudWatch accounted for more than 50% of the monthly AWS service costs, as shown in Figure 4.

Analyzing Top 3 Cost Drivers for CloudWatch Service

“Based on my Cost explorer for the past month, can you identify the top 3 AWS Usage or resources that contributed the most to my CloudWatch costs?”

Figure 5. Analyzing Cost Drivers for CloudWatch Service

The in-depth analysis, as shown in Figure 5, uncovers critical insights into the CloudWatch Logs ingestion within the CloudWatch service. It offers strategic recommendations to optimize costs. These recommendations include reviewing log retention policies, implementing log filtering techniques, optimizing CloudWatch Logs Insights queries, and considering log archival strategies.

Analyzing Top Log Groups Contributing to CloudWatch Cost

“Thank you for identifying that the ‘USE1-VendedLog-Bytes’ cost is the largest contributor to my CloudWatch costs. Can you further break down this cost by the top log groups that are driving this expense?”

Figure 6. Analyzing Log Groups Contributing to CloudWatch Cost

As shown in Figure 6 above, the analysis revealed that a single log group named “/aws/lambda/CloudWatchLambda” was responsible for 99.9% of the organization’s log storage costs. The recommendation focuses on setting targeted retention periods, investigating the root cause of excessive logging in the specific AWS Lambda function, and continuously monitoring cost changes.

CloudWatch Lambda Log Cost Analysis Investigation

“Investigate the CloudWatchLambda function configuration and explore log optimization strategies”

Figure 7. CloudWatch Lambda Function Excessive Logging Cost Analysis

As shown in Figure 7 above, the analysis revealed that the CloudWatchLambda function is generating massive log costs due to excessive logging of repetitive CSV data at both DEBUG and INFO levels with no retention policy.

Analyzing Idle CloudWatch Alarms to Optimize Costs

“Show me CloudWatch alarms that haven’t triggered in 90 days but are still incurring charges”

Figure 8. Analyzing CloudWatch Alarms to Optimize Costs

As shown in Figure 8, revealing critical insights into inactive monitoring resources. The recommendations focus on deleting unnecessary alarms, reviewing Amazon DynamoDB configurations, and maintaining effective monitoring strategies to optimize cloud monitoring costs.

Conclusion

A comprehensive approach to Amazon CloudWatch cost analysis using Amazon Q CLI, Billing and Cost Management MCP server, and the Amazon CloudWatch MCP server can perform detailed analysis. By leveraging natural language prompts, we showcased how you can transform complex cloud monitoring cost management into actionable insights.

The key steps involved using Amazon Q CLI to generate detailed cost breakdowns, identify primary cost drivers, and provide targeted optimization recommendations. We explored multiple dimensions of CloudWatch expenses in the example and demonstrated strategies for reducing costs, such as implementing retention policies, investigating logging practices, and inactive monitoring resources.

By combining Amazon Q’s capabilities with strategic cloud cost management techniques, you can achieve detailed insights into your infrastructure expenses. The core benefit is the ability to identify cost optimization opportunities through natural language, understand usage patterns, and make data-driven decisions about cloud resource management.

We encourage you to implement the MCP servers in your AWS environment to enhance financial visibility and operational efficiency. By taking advantage of this approach, you can improve your cloud cost management, ensure more efficient resource utilization, and optimize your infrastructure spending. To get started, explore the Amazon Q CLI capabilities and apply the cost analysis strategies discussed above. For more information about AWS cost management, visit the AWS Cost Management documentation.

Aneesh Varghese

Aneesh Varghese

Aneesh Varghese is a Senior Technical Account Manager at AWS with more than 19 years of Information Technology industry experience. Aneesh supports enterprise customers in cost optimization strategies, Cloud operations, MLOps, providing advocacy and strategic technical guidance to help plan and build solutions using AWS best practices. Outside of work, Aneesh likes to spend time with family, play Basketball and Badminton

Anjani Reddy

Anjani Reddy

Anjani is a Sr. Solutions Architect at AWS. She works with Enterprise customers to provide operational guidance to innovate and build a secure, scalable cloud on the AWS platform. Outside of work, she is an Indian classical & salsa dancer, loves to travel and Volunteers for American Red Cross & Hands on Atlanta.