get_cost_anomalies
Identify unusual spending patterns in AWS costs by retrieving anomalies detected by AWS Cost Anomaly Detection for specified date ranges.
Instructions
Retrieves cost anomalies detected by AWS Cost Anomaly Detection.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| start_date | Yes | Start date (YYYY-MM-DD). | |
| end_date | Yes | End date (YYYY-MM-DD). |
Implementation Reference
- src/index.ts:245-256 (registration)Tool registration in the ListTools handler, defining name, description, and input schema.{ name: "get_cost_anomalies", description: "Retrieves cost anomalies detected by AWS Cost Anomaly Detection.", inputSchema: { type: "object", properties: { start_date: { type: "string", description: "Start date (YYYY-MM-DD)." }, end_date: { type: "string", description: "End date (YYYY-MM-DD)." } }, required: ["start_date", "end_date"] } },
- src/index.ts:248-255 (schema)Input schema for the get_cost_anomalies tool, requiring start_date and end_date.inputSchema: { type: "object", properties: { start_date: { type: "string", description: "Start date (YYYY-MM-DD)." }, end_date: { type: "string", description: "End date (YYYY-MM-DD)." } }, required: ["start_date", "end_date"] }
- src/index.ts:1079-1096 (handler)Handler implementation in CallToolRequestSchema that fetches cost anomalies using AWS CostExplorerClient's GetAnomaliesCommand and formats the response.if (name === "get_cost_anomalies") { const command = new GetAnomaliesCommand({ DateInterval: { StartDate: (args as any).start_date, EndDate: (args as any).end_date }, MaxResults: 20 }); const response = await costExplorerClient.send(command); const anomalies = response.Anomalies?.map(a => ({ AnomalyId: a.AnomalyId, AnomalyScore: a.AnomalyScore, ImpactTotal: a.Impact?.TotalImpact, MonitorArn: a.MonitorArn, RootCauses: a.RootCauses, Date: a.AnomalyEndDate })) || []; return { content: [{ type: "text", text: JSON.stringify(anomalies, null, 2) }] }; }
- src/index.ts:58-58 (helper)Initialization of the AWS CostExplorerClient used by the get_cost_anomalies handler.const costExplorerClient = new CostExplorerClient({});
- src/index.ts:24-24 (helper)Import of GetAnomaliesCommand and CostExplorerClient from AWS SDK.import { CostExplorerClient, GetCostAndUsageCommand, GetCostForecastCommand, GetAnomaliesCommand, GetSavingsPlansUtilizationCommand, GetReservationUtilizationCommand } from "@aws-sdk/client-cost-explorer";