Back to Aws Sdk Js V3

@aws-sdk/client-cloudwatch

clients/client-cloudwatch/README.md

3.1076.032.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 enables you to publish, monitor, and manage various metrics, as well as configure alarm actions based on data from metrics. This guide provides detailed information about CloudWatch actions, data types, parameters, and errors. For more information about CloudWatch features, see <a href="https://aws.amazon.com/cloudwatch">Amazon CloudWatch</a> and the <i>Amazon CloudWatch User Guide</i>.</p> <p>For information about the metrics that other Amazon Web Services products send to CloudWatch, see the <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/aws-services-cloudwatch-metrics.html">Amazon CloudWatch Metrics and Dimensions Reference</a> in the <i>Amazon CloudWatch User Guide</i>.</p> <p>Use the following links to get started using the CloudWatch Query API:</p> <p>: An alphabetical list of all CloudWatch actions.</p> <p>: An alphabetical list of all CloudWatch data types.</p> <p> <a>CommonParameters</a>: Parameters that all Query actions can use.</p> <p> <a>CommonErrors</a>: Client and server errors that all actions can return.</p> <p> <a href="https://docs.aws.amazon.com/general/latest/gr/rande.html#cw_region">Regions and Endpoints</a>: Supported regions and endpoints for all Amazon Web Services products.</p> <p>Alternatively, you can use one of the <a href="https://aws.amazon.com/tools/#sdk">Amazon Web Services SDKs</a> to access CloudWatch using an API tailored to your programming language or platform.</p> <p>Developers in the Amazon Web Services developer community also provide their own libraries, which you can find at the following Amazon Web Services developer centers:</p> <p> <a href="http://aws.amazon.com/java/">Java Developer Center</a> </p> <p> <a href="http://aws.amazon.com/javascript/">JavaScript Developer Center</a> </p> <p> <a href="http://aws.amazon.com/mobile/">Amazon Web Services Mobile Services</a> </p> <p> <a href="http://aws.amazon.com/php/">PHP Developer Center</a> </p> <p> <a href="http://aws.amazon.com/python/">Python Developer Center</a> </p> <p> <a href="http://aws.amazon.com/ruby/">Ruby Developer Center</a> </p> <p> <a href="http://aws.amazon.com/net/">Windows and .NET Developer Center</a> </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> AssociateDatasetKmsKey </summary>

Command API Reference / Input / Output

</details> <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> DisassociateDatasetKmsKey </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> GetDataset </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> PutLogAlarm </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>