Skip to content

Resource: awsCeAnomalySubscription

Provides a CE Anomaly Subscription.

Example Usage

Basic Example

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsCeAnomalyMonitorTest = new aws.ceAnomalyMonitor.CeAnomalyMonitor(
  this,
  "test",
  {
    monitorDimension: "SERVICE",
    monitorType: "DIMENSIONAL",
    name: "AWSServiceMonitor",
  }
);
const awsCeAnomalySubscriptionTest =
  new aws.ceAnomalySubscription.CeAnomalySubscription(this, "test_1", {
    frequency: "DAILY",
    monitorArnList: [awsCeAnomalyMonitorTest.arn],
    name: "DAILYSUBSCRIPTION",
    subscriber: [
      {
        address: "abc@example.com",
        type: "EMAIL",
      },
    ],
    threshold: 100,
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsCeAnomalySubscriptionTest.overrideLogicalId("test");

Threshold Expression

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.ceAnomalySubscription.CeAnomalySubscription(this, "test", {
  frequency: "DAILY",
  monitorArnList: ["${aws_ce_anomaly_monitor.test.arn}"],
  name: "AWSServiceMonitor",
  subscriber: [
    {
      address: "abc@example.com",
      type: "EMAIL",
    },
  ],
  thresholdExpression: {
    dimension: {
      key: "ANOMALY_TOTAL_IMPACT_ABSOLUTE",
      matchOptions: ["GREATER_THAN_OR_EQUAL"],
      values: ["100.0"],
    },
  },
});

SNS Example

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsCeAnomalyMonitorAnomalyMonitor =
  new aws.ceAnomalyMonitor.CeAnomalyMonitor(this, "anomaly_monitor", {
    monitorDimension: "SERVICE",
    monitorType: "DIMENSIONAL",
    name: "AWSServiceMonitor",
  });
const awsSnsTopicCostAnomalyUpdates = new aws.snsTopic.SnsTopic(
  this,
  "cost_anomaly_updates",
  {
    name: "CostAnomalyUpdates",
  }
);
const dataAwsIamPolicyDocumentSnsTopicPolicy =
  new aws.dataAwsIamPolicyDocument.DataAwsIamPolicyDocument(
    this,
    "sns_topic_policy",
    {
      policyId: "__default_policy_ID",
      statement: [
        {
          actions: ["SNS:Publish"],
          effect: "Allow",
          principals: [
            {
              identifiers: ["costalerts.amazonaws.com"],
              type: "Service",
            },
          ],
          resources: [awsSnsTopicCostAnomalyUpdates.arn],
          sid: "AWSAnomalyDetectionSNSPublishingPermissions",
        },
        {
          actions: [
            "SNS:Subscribe",
            "SNS:SetTopicAttributes",
            "SNS:RemovePermission",
            "SNS:Receive",
            "SNS:Publish",
            "SNS:ListSubscriptionsByTopic",
            "SNS:GetTopicAttributes",
            "SNS:DeleteTopic",
            "SNS:AddPermission",
          ],
          condition: [
            {
              test: "StringEquals",
              values: ["${var.account-id}"],
              variable: "AWS:SourceOwner",
            },
          ],
          effect: "Allow",
          principals: [
            {
              identifiers: ["*"],
              type: "AWS",
            },
          ],
          resources: [awsSnsTopicCostAnomalyUpdates.arn],
          sid: "__default_statement_ID",
        },
      ],
    }
  );
const awsSnsTopicPolicyDefault = new aws.snsTopicPolicy.SnsTopicPolicy(
  this,
  "default",
  {
    arn: awsSnsTopicCostAnomalyUpdates.arn,
    policy: dataAwsIamPolicyDocumentSnsTopicPolicy.json,
  }
);
new aws.ceAnomalySubscription.CeAnomalySubscription(
  this,
  "realtime_subscription",
  {
    depends_on: [`\${${awsSnsTopicPolicyDefault.fqn}}`],
    frequency: "IMMEDIATE",
    monitorArnList: [awsCeAnomalyMonitorAnomalyMonitor.arn],
    name: "RealtimeAnomalySubscription",
    subscriber: [
      {
        address: awsSnsTopicCostAnomalyUpdates.arn,
        type: "SNS",
      },
    ],
    threshold: 0,
  }
);

Argument Reference

The following arguments are required:

  • accountId - (Optional) The unique identifier for the AWS account in which the anomaly subscription ought to be created.
  • frequency - (Required) The frequency that anomaly reports are sent. Valid Values: daily | immediate | weekly.
  • monitorArnList - (Required) A list of cost anomaly monitors.
  • name - (Required) The name for the subscription.
  • subscriber - (Required) A subscriber configuration. Multiple subscribers can be defined.
  • type - (Required) The type of subscription. Valid Values: sns | email.
  • address - (Required) The address of the subscriber. If type is sns, this will be the arn of the sns topic. If type is email, this will be the destination email address.
  • threshold - (Optional) The dollar value that triggers a notification if the threshold is exceeded. Depracated, use thresholdExpression instead.
  • thresholdExpression - (Optional) An Expression object used to specify the anomalies that you want to generate alerts for. See Threshold Expression.
  • tags - (Optional) A map of tags to assign to the resource. If configured with a provider defaultTags configuration block present, tags with matching keys will overwrite those defined at the provider-level.

Threshold Expression

  • and - (Optional) Return results that match both Dimension objects.
  • costCategory - (Optional) Configuration block for the filter that's based on values. See Cost Category below.
  • dimension - (Optional) Configuration block for the specific Dimension to use for.
  • not - (Optional) Return results that match both Dimension object.
  • or - (Optional) Return results that match both Dimension object.
  • tags - (Optional) Configuration block for the specific Tag to use for. See Tags below.

Cost Category

  • key - (Optional) Unique name of the Cost Category.
  • matchOptions - (Optional) Match options that you can use to filter your results. MatchOptions is only applicable for actions related to cost category. The default values for MatchOptions is equals and CASE_SENSITIVE. Valid values are: equals, absent, STARTS_WITH, ENDS_WITH, contains, CASE_SENSITIVE, CASE_INSENSITIVE.
  • values - (Optional) Specific value of the Cost Category.

Dimension

  • key - (Optional) Unique name of the Cost Category.
  • matchOptions - (Optional) Match options that you can use to filter your results. MatchOptions is only applicable for actions related to cost category. The default values for MatchOptions is equals and CASE_SENSITIVE. Valid values are: equals, absent, STARTS_WITH, ENDS_WITH, contains, CASE_SENSITIVE, CASE_INSENSITIVE.
  • values - (Optional) Specific value of the Cost Category.

Tags

  • key - (Optional) Key for the tag.
  • matchOptions - (Optional) Match options that you can use to filter your results. MatchOptions is only applicable for actions related to cost category. The default values for MatchOptions is equals and CASE_SENSITIVE. Valid values are: equals, absent, STARTS_WITH, ENDS_WITH, contains, CASE_SENSITIVE, CASE_INSENSITIVE.
  • values - (Optional) Specific value of the Cost Category.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • arn - ARN of the anomaly subscription.
  • id - Unique ID of the anomaly subscription. Same as arn.
  • tagsAll - A map of tags assigned to the resource, including those inherited from the provider defaultTags configuration block.

Import

awsCeAnomalySubscription can be imported using the id, e.g.

$ terraform import aws_ce_anomaly_subscription.example AnomalySubscriptionARN