> **Experimental**
>
> `@aws-cdk/aws-iot-actions-alpha` is an [**experimental**](https://docs.aws.amazon.com/cdk/api/stability.html) (alpha) package: its API may change in any release, without a major version bump.
# CloudWatchPutMetricActionProps

Configuration properties of an action for CloudWatch metric.

Extends: [CommonActionProps](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-iot-actions-alpha.CommonActionProps.html)
Used as props by: [CloudWatchPutMetricAction](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-iot-actions-alpha.CloudWatchPutMetricAction.html)

- Stability: [Experimental](https://docs.aws.amazon.com/cdk/api/stability.html)
- Source: [`lib/cloudwatch-put-metric-action.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/@aws-cdk/aws-iot-actions-alpha/lib/cloudwatch-put-metric-action.ts#L9)

## Example

TypeScript:

```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:

```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:

```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();
```

C# / .NET:

```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}"
        }) }
});
```

Golang:

```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}"),
		}),
	},
})
```

## Properties

- `metricName`: string (required) — The CloudWatch metric name.

  Supports substitution templates.

- `metricNamespace`: string (required) — The CloudWatch metric namespace name.

  Supports substitution templates.

- `metricTimestamp`: string — A string that contains the timestamp, expressed in seconds in Unix epoch time.

  **Default:** none -- Defaults to the current Unix epoch time.

  Supports substitution templates.

- `metricUnit`: string (required) — The metric unit supported by CloudWatch.

  Supports substitution templates.

- `metricValue`: string (required) — A string that contains the CloudWatch metric value.

  Supports substitution templates.

- `role`: [IRole](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The IAM role that allows access to AWS service.

  **Default:** a new role will be created
