list_cloudwatch_alarms
Retrieve and filter AWS CloudWatch alarms by state to monitor system health and performance metrics.
Instructions
Lists CloudWatch alarms, optionally filtering by state.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| state | No | Filter alarms by state. |
Implementation Reference
- src/index.ts:939-958 (handler)The handler function for the 'list_cloudwatch_alarms' tool. It optionally filters CloudWatch alarms by state using DescribeAlarmsCommand on the cloudWatchClient, maps relevant fields (AlarmName, StateValue, StateReason, MetricName, Namespace), and returns them as JSON.if (name === "list_cloudwatch_alarms") { const state = (args as any)?.state; const commandInput: any = {}; if (state) commandInput.StateValue = state; const command = new DescribeAlarmsCommand(commandInput); const response = await cloudWatchClient.send(command); const alarms = response.MetricAlarms?.map(a => ({ AlarmName: a.AlarmName, StateValue: a.StateValue, StateReason: a.StateReason, MetricName: a.MetricName, Namespace: a.Namespace })) || []; return { content: [{ type: "text", text: JSON.stringify(alarms, null, 2) }] }; }
- src/index.ts:161-173 (registration)Registration of the 'list_cloudwatch_alarms' tool in the ListTools response, including name, description, and input schema definition.name: "list_cloudwatch_alarms", description: "Lists CloudWatch alarms, optionally filtering by state.", inputSchema: { type: "object", properties: { state: { type: "string", enum: ["OK", "ALARM", "INSUFFICIENT_DATA"], description: "Filter alarms by state." } } } },
- src/index.ts:161-173 (schema)Input schema for the 'list_cloudwatch_alarms' tool, defining optional 'state' parameter with valid enum values.name: "list_cloudwatch_alarms", description: "Lists CloudWatch alarms, optionally filtering by state.", inputSchema: { type: "object", properties: { state: { type: "string", enum: ["OK", "ALARM", "INSUFFICIENT_DATA"], description: "Filter alarms by state." } } } },
- src/index.ts:57-57 (helper)Initialization of the CloudWatchClient used by the list_cloudwatch_alarms handler.const cloudWatchClient = new CloudWatchClient({});
- src/index.ts:23-23 (helper)Import of CloudWatchClient and DescribeAlarmsCommand required for the tool implementation.import { CloudWatchClient, DescribeAlarmsCommand } from "@aws-sdk/client-cloudwatch";