Skip to content
v2.275.0

Experimental

@aws-cdk/aws-iot-actions-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.

CloudWatchPutMetricAction Class ​

The action to capture an Amazon CloudWatch metric.

Example ​

ts
const topicRule = new iot.TopicRule(this, 'TopicRule', {
  sql: iot.IotSql.fromStringAsVer20160323(
    "SELECT topic(2) as device_id, namespace, unit, value, timestamp FROM 'device/+/data'",
  ),
  actions: [
    new actions.CloudWatchPutMetricAction({
      metricName: '${topic(2)}',
      metricNamespace: '${namespace}',
      metricUnit: '${unit}',
      metricValue: '${value}',
      metricTimestamp: '${timestamp}',
    }),
  ],
});
python
topic_rule = iot.TopicRule(self, "TopicRule",
    sql=iot.IotSql.from_string_as_ver20160323("SELECT topic(2) as device_id, namespace, unit, value, timestamp FROM 'device/+/data'"),
    actions=[
        actions.CloudWatchPutMetricAction(
            metric_name="${topic(2)}",
            metric_namespace="${namespace}",
            metric_unit="${unit}",
            metric_value="${value}",
            metric_timestamp="${timestamp}"
        )
    ]
)
java
TopicRule topicRule = TopicRule.Builder.create(this, "TopicRule")
        .sql(IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id, namespace, unit, value, timestamp FROM 'device/+/data'"))
        .actions(List.of(
            CloudWatchPutMetricAction.Builder.create()
                    .metricName("${topic(2)}")
                    .metricNamespace("${namespace}")
                    .metricUnit("${unit}")
                    .metricValue("${value}")
                    .metricTimestamp("${timestamp}")
                    .build()))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.AWS.IoT.Actions.Alpha
var topicRule = new TopicRule(this, "TopicRule", new TopicRuleProps {
    Sql = IotSql.FromStringAsVer20160323("SELECT topic(2) as device_id, namespace, unit, value, timestamp FROM 'device/+/data'"),
    Actions = new [] {
        new CloudWatchPutMetricAction(new CloudWatchPutMetricActionProps {
            MetricName = "${topic(2)}",
            MetricNamespace = "${namespace}",
            MetricUnit = "${unit}",
            MetricValue = "${value}",
            MetricTimestamp = "${timestamp}"
        }) }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdkiotactionsalpha/v2
topicRule := iot.NewTopicRule(this, jsii.String("TopicRule"), &TopicRuleProps{
	Sql: iot.IotSql_FromStringAsVer20160323(jsii.String("SELECT topic(2) as device_id, namespace, unit, value, timestamp FROM 'device/+/data'")),
	Actions: []IAction{
		actions.NewCloudWatchPutMetricAction(&CloudWatchPutMetricActionProps{
			MetricName: jsii.String("${topic(2)}"),
			MetricNamespace: jsii.String("${namespace}"),
			MetricUnit: jsii.String("${unit}"),
			MetricValue: jsii.String("${value}"),
			MetricTimestamp: jsii.String("${timestamp}"),
		}),
	},
})

Initializer ​

ts
new CloudWatchPutMetricAction(props: CloudWatchPutMetricActionProps)
python
CloudWatchPutMetricAction(props: CloudWatchPutMetricActionProps)
java
new CloudWatchPutMetricAction(CloudWatchPutMetricActionProps props)
csharp
new CloudWatchPutMetricAction(CloudWatchPutMetricActionProps props)
go
NewCloudWatchPutMetricAction(Props CloudWatchPutMetricActionProps)