Back to Aws Sdk Js V3

@aws-sdk/client-cloudwatch

clients/client-cloudwatch/README.md

3.1043.029.4 KB
Original Source
<!-- generated file, do not edit directly -->

@aws-sdk/client-cloudwatch

Description

AWS SDK for JavaScript CloudWatch Client for Node.js, Browser and React Native.

<p>Amazon CloudWatch monitors your Amazon Web Services (Amazon Web Services) resources and the applications you run on Amazon Web Services in real time. You can use CloudWatch to collect and track metrics, which are the variables you want to measure for your resources and applications.</p> <p>CloudWatch alarms send notifications or automatically change the resources you are monitoring based on rules that you define. For example, you can monitor the CPU usage and disk reads and writes of your Amazon EC2 instances. Then, use this data to determine whether you should launch additional instances to handle increased load. You can also use this data to stop under-used instances to save money.</p> <p>In addition to monitoring the built-in metrics that come with Amazon Web Services, you can monitor your own custom metrics. With CloudWatch, you gain system-wide visibility into resource utilization, application performance, and operational health.</p>

Installing

To install this package, use the CLI of your favorite package manager:

  • npm install @aws-sdk/client-cloudwatch
  • yarn add @aws-sdk/client-cloudwatch
  • pnpm add @aws-sdk/client-cloudwatch

Getting Started

Import

The AWS SDK is modulized by clients and commands. To send a request, you only need to import the CloudWatchClient and the commands you need, for example ListMetricsCommand:

js
// ES5 example
const { CloudWatchClient, ListMetricsCommand } = require("@aws-sdk/client-cloudwatch");
ts
// ES6+ example
import { CloudWatchClient, ListMetricsCommand } from "@aws-sdk/client-cloudwatch";

Usage

To send a request:

  • Instantiate a client with configuration (e.g. credentials, region).
  • Instantiate a command with input parameters.
  • Call the send operation on the client, providing the command object as input.
js
const client = new CloudWatchClient({ region: "REGION" });

const params = { /** input parameters */ };
const command = new ListMetricsCommand(params);

Supported Message Protocols

This client supports multiple protocols.

The default for this client is AWS JSON (RPC) 1.0.

We have selected this default based on our evaluation of the performance characteristics of this protocol format in JavaScript. You don't need to change it, but you have the option to do so, for example to support existing integrations or tests. Selecting a non-default protocol changes the format of the data sent over the network, but does not affect how you interact with the client using JavaScript objects.

Install the @aws-sdk/config package to access alternate protocols.

See AWS Protocols for more information.

AWS JSON (RPC) 1.0

This protocol uses JSON payloads.

js
import { AwsJson1_0Protocol } from "@aws-sdk/config/protocol";

const client = new CloudWatchClient({
  protocol: AwsJson1_0Protocol
});
AWS Query

This protocol uses query format requests and XML responses.

js
import { AwsQueryProtocol } from "@aws-sdk/config/protocol";

const client = new CloudWatchClient({
  protocol: AwsQueryProtocol
});
AWS Query

This protocol uses query format requests and XML responses.

js
import { AwsQueryProtocol } from "@aws-sdk/config/protocol";

const client = new CloudWatchClient({
  protocol: AwsQueryProtocol
});
Smithy RPC v2 CBOR

This protocol uses CBOR payloads.

js
import { AwsSmithyRpcV2CborProtocol } from "@aws-sdk/config/protocol";

const client = new CloudWatchClient({
  protocol: AwsSmithyRpcV2CborProtocol
});

Async/await

We recommend using the await operator to wait for the promise returned by send operation as follows:

js
// async/await.
try {
  const data = await client.send(command);
  // process data.
} catch (error) {
  // error handling.
} finally {
  // finally.
}

Promises

You can also use Promise chaining.

js
client
  .send(command)
  .then((data) => {
    // process data.
  })
  .catch((error) => {
    // error handling.
  })
  .finally(() => {
    // finally.
  });

Aggregated client

The aggregated client class is exported from the same package, but without the "Client" suffix.

CloudWatch extends CloudWatchClient and additionally supports all operations, waiters, and paginators as methods. This style may be familiar to you from the AWS SDK for JavaScript v2.

If you are bundling the AWS SDK, we recommend using only the bare-bones client (CloudWatchClient). More details are in the blog post on modular packages in AWS SDK for JavaScript.

ts
import { CloudWatch } from "@aws-sdk/client-cloudwatch";

const client = new CloudWatch({ region: "REGION" });

// async/await.
try {
  const data = await client.listMetrics(params);
  // process data.
} catch (error) {
  // error handling.
}

// Promises.
client
  .listMetrics(params)
  .then((data) => {
    // process data.
  })
  .catch((error) => {
    // error handling.
  });

// callbacks (not recommended).
client.listMetrics(params, (err, data) => {
  // process err and data.
});

Troubleshooting

When the service returns an exception, the error will include the exception information, as well as response metadata (e.g. request id).

js
try {
  const data = await client.send(command);
  // process data.
} catch (error) {
  const { requestId, cfId, extendedRequestId } = error.$metadata;
  console.log({ requestId, cfId, extendedRequestId });
  /**
   * The keys within exceptions are also parsed.
   * You can access them by specifying exception names:
   * if (error.name === 'SomeServiceException') {
   *     const value = error.specialKeyInException;
   * }
   */
}

See also docs/ERROR_HANDLING.

Getting Help

Please use these community resources for getting help. We use GitHub issues for tracking bugs and feature requests, but have limited bandwidth to address them.

To test your universal JavaScript code in Node.js, browser and react-native environments, visit our code samples repo.

Contributing

This client code is generated automatically. Any modifications will be overwritten the next time the @aws-sdk/client-cloudwatch package is updated. To contribute to client you can check our generate clients scripts.

License

This SDK is distributed under the Apache License, Version 2.0, see LICENSE for more information.

Client Commands (Operations List)

<details> <summary> DeleteAlarmMuteRule </summary>

Command API Reference / Input / Output

</details> <details> <summary> DeleteAlarms </summary>

Command API Reference / Input / Output

</details> <details> <summary> DeleteAnomalyDetector </summary>

Command API Reference / Input / Output

</details> <details> <summary> DeleteDashboards </summary>

Command API Reference / Input / Output

</details> <details> <summary> DeleteInsightRules </summary>

Command API Reference / Input / Output

</details> <details> <summary> DeleteMetricStream </summary>

Command API Reference / Input / Output

</details> <details> <summary> DescribeAlarmContributors </summary>

Command API Reference / Input / Output

</details> <details> <summary> DescribeAlarmHistory </summary>

Command API Reference / Input / Output

</details> <details> <summary> DescribeAlarms </summary>

Command API Reference / Input / Output

</details> <details> <summary> DescribeAlarmsForMetric </summary>

Command API Reference / Input / Output

</details> <details> <summary> DescribeAnomalyDetectors </summary>

Command API Reference / Input / Output

</details> <details> <summary> DescribeInsightRules </summary>

Command API Reference / Input / Output

</details> <details> <summary> DisableAlarmActions </summary>

Command API Reference / Input / Output

</details> <details> <summary> DisableInsightRules </summary>

Command API Reference / Input / Output

</details> <details> <summary> EnableAlarmActions </summary>

Command API Reference / Input / Output

</details> <details> <summary> EnableInsightRules </summary>

Command API Reference / Input / Output

</details> <details> <summary> GetAlarmMuteRule </summary>

Command API Reference / Input / Output

</details> <details> <summary> GetDashboard </summary>

Command API Reference / Input / Output

</details> <details> <summary> GetInsightRuleReport </summary>

Command API Reference / Input / Output

</details> <details> <summary> GetMetricData </summary>

Command API Reference / Input / Output

</details> <details> <summary> GetMetricStatistics </summary>

Command API Reference / Input / Output

</details> <details> <summary> GetMetricStream </summary>

Command API Reference / Input / Output

</details> <details> <summary> GetMetricWidgetImage </summary>

Command API Reference / Input / Output

</details> <details> <summary> GetOTelEnrichment </summary>

Command API Reference / Input / Output

</details> <details> <summary> ListAlarmMuteRules </summary>

Command API Reference / Input / Output

</details> <details> <summary> ListDashboards </summary>

Command API Reference / Input / Output

</details> <details> <summary> ListManagedInsightRules </summary>

Command API Reference / Input / Output

</details> <details> <summary> ListMetrics </summary>

Command API Reference / Input / Output

</details> <details> <summary> ListMetricStreams </summary>

Command API Reference / Input / Output

</details> <details> <summary> ListTagsForResource </summary>

Command API Reference / Input / Output

</details> <details> <summary> PutAlarmMuteRule </summary>

Command API Reference / Input / Output

</details> <details> <summary> PutAnomalyDetector </summary>

Command API Reference / Input / Output

</details> <details> <summary> PutCompositeAlarm </summary>

Command API Reference / Input / Output

</details> <details> <summary> PutDashboard </summary>

Command API Reference / Input / Output

</details> <details> <summary> PutInsightRule </summary>

Command API Reference / Input / Output

</details> <details> <summary> PutManagedInsightRules </summary>

Command API Reference / Input / Output

</details> <details> <summary> PutMetricAlarm </summary>

Command API Reference / Input / Output

</details> <details> <summary> PutMetricData </summary>

Command API Reference / Input / Output

</details> <details> <summary> PutMetricStream </summary>

Command API Reference / Input / Output

</details> <details> <summary> SetAlarmState </summary>

Command API Reference / Input / Output

</details> <details> <summary> StartMetricStreams </summary>

Command API Reference / Input / Output

</details> <details> <summary> StartOTelEnrichment </summary>

Command API Reference / Input / Output

</details> <details> <summary> StopMetricStreams </summary>

Command API Reference / Input / Output

</details> <details> <summary> StopOTelEnrichment </summary>

Command API Reference / Input / Output

</details> <details> <summary> TagResource </summary>

Command API Reference / Input / Output

</details> <details> <summary> UntagResource </summary>

Command API Reference / Input / Output

</details>