PutAnomalyDetectorCommand

Creates an anomaly detection model for a CloudWatch metric. You can use the model to display a band of expected normal values when the metric is graphed.

If you have enabled unified cross-account observability, and this account is a monitoring account, the metric can be in the same account or a source account. You can specify the account ID in the object you specify in the SingleMetricAnomalyDetector parameter.

For more information, see CloudWatch Anomaly Detection .

Example Syntax

Use a bare-bones client and the command you need to make an API call.

import { CloudWatchClient, PutAnomalyDetectorCommand } from "@aws-sdk/client-cloudwatch"; // ES Modules import
// const { CloudWatchClient, PutAnomalyDetectorCommand } = require("@aws-sdk/client-cloudwatch"); // CommonJS import
const client = new CloudWatchClient(config);
const input = { // PutAnomalyDetectorInput
  Namespace: "STRING_VALUE",
  MetricName: "STRING_VALUE",
  Dimensions: [ // Dimensions
    { // Dimension
      Name: "STRING_VALUE", // required
      Value: "STRING_VALUE", // required
    },
  ],
  Stat: "STRING_VALUE",
  Configuration: { // AnomalyDetectorConfiguration
    ExcludedTimeRanges: [ // AnomalyDetectorExcludedTimeRanges
      { // Range
        StartTime: new Date("TIMESTAMP"), // required
        EndTime: new Date("TIMESTAMP"), // required
      },
    ],
    MetricTimezone: "STRING_VALUE",
  },
  MetricCharacteristics: { // MetricCharacteristics
    PeriodicSpikes: true || false,
  },
  SingleMetricAnomalyDetector: { // SingleMetricAnomalyDetector
    AccountId: "STRING_VALUE",
    Namespace: "STRING_VALUE",
    MetricName: "STRING_VALUE",
    Dimensions: [
      {
        Name: "STRING_VALUE", // required
        Value: "STRING_VALUE", // required
      },
    ],
    Stat: "STRING_VALUE",
  },
  MetricMathAnomalyDetector: { // MetricMathAnomalyDetector
    MetricDataQueries: [ // MetricDataQueries
      { // MetricDataQuery
        Id: "STRING_VALUE", // required
        MetricStat: { // MetricStat
          Metric: { // Metric
            Namespace: "STRING_VALUE",
            MetricName: "STRING_VALUE",
            Dimensions: "<Dimensions>",
          },
          Period: Number("int"), // required
          Stat: "STRING_VALUE", // required
          Unit: "Seconds" || "Microseconds" || "Milliseconds" || "Bytes" || "Kilobytes" || "Megabytes" || "Gigabytes" || "Terabytes" || "Bits" || "Kilobits" || "Megabits" || "Gigabits" || "Terabits" || "Percent" || "Count" || "Bytes/Second" || "Kilobytes/Second" || "Megabytes/Second" || "Gigabytes/Second" || "Terabytes/Second" || "Bits/Second" || "Kilobits/Second" || "Megabits/Second" || "Gigabits/Second" || "Terabits/Second" || "Count/Second" || "None",
        },
        Expression: "STRING_VALUE",
        Label: "STRING_VALUE",
        ReturnData: true || false,
        Period: Number("int"),
        AccountId: "STRING_VALUE",
      },
    ],
  },
};
const command = new PutAnomalyDetectorCommand(input);
const response = await client.send(command);
// {};

PutAnomalyDetectorCommand Input

See PutAnomalyDetectorCommandInput for more details

Parameter
Type
Description
Configuration
AnomalyDetectorConfiguration | undefined

The configuration specifies details about how the anomaly detection model is to be trained, including time ranges to exclude when training and updating the model. You can specify as many as 10 time ranges.

The configuration can also include the time zone to use for the metric.

Dimensions
Dimension[] | undefined

The metric dimensions to create the anomaly detection model for.

MetricCharacteristics
MetricCharacteristics | undefined

Use this object to include parameters to provide information about your metric to CloudWatch to help it build more accurate anomaly detection models. Currently, it includes the PeriodicSpikes parameter.

MetricMathAnomalyDetector
MetricMathAnomalyDetector | undefined

The metric math anomaly detector to be created.

When using MetricMathAnomalyDetector, you cannot include the following parameters in the same operation:

  • Dimensions

  • MetricName

  • Namespace

  • Stat

  • the SingleMetricAnomalyDetector parameters of PutAnomalyDetectorInput

Instead, specify the metric math anomaly detector attributes as part of the property MetricMathAnomalyDetector.

MetricName
string | undefined

The name of the metric to create the anomaly detection model for.

Namespace
string | undefined

The namespace of the metric to create the anomaly detection model for.

SingleMetricAnomalyDetector
SingleMetricAnomalyDetector | undefined

A single metric anomaly detector to be created.

When using SingleMetricAnomalyDetector, you cannot include the following parameters in the same operation:

  • Dimensions

  • MetricName

  • Namespace

  • Stat

  • the MetricMathAnomalyDetector parameters of PutAnomalyDetectorInput

Instead, specify the single metric anomaly detector attributes as part of the property SingleMetricAnomalyDetector.

Stat
string | undefined

The statistic to use for the metric and the anomaly detection model.

PutAnomalyDetectorCommand Output

Parameter
Type
Description
$metadata
Required
ResponseMetadata
Metadata pertaining to this request.

Throws

Name
Fault
Details
InternalServiceFault
server

Request processing has failed due to some unknown error, exception, or failure.

InvalidParameterCombinationException
client

Parameters were used together that cannot be used together.

InvalidParameterValueException
client

The value of an input parameter is bad or out-of-range.

LimitExceededException
client

The operation exceeded one or more limits.

MissingRequiredParameterException
client

An input parameter that is required is missing.

CloudWatchServiceException
Base exception class for all service exceptions from CloudWatch service.