

End of support notice: On May 20, 2026, Amazon will end support for Amazon IoT Events. After May 20, 2026, you will no longer be able to access the Amazon IoT Events console or Amazon IoT Events resources. For more information, see [Amazon IoT Events end of support](https://docs.amazonaws.cn/iotevents/latest/developerguide/iotevents-end-of-support.html).

# Migration procedure for Amazon IoT SiteWise alarms in Amazon IoT Events
<a name="eos-procedure-alarms"></a>

This section describes alternative solutions that deliver similar alarm functionality as you migrate away from Amazon IoT Events.

For Amazon IoT SiteWise properties that use Amazon IoT Events alarms, you can migrate to a solution using CloudWatch alarms. This approach provides robust monitoring capabilities with established SLAs and additional features like anomaly detection and grouped alarms.

## Comparing architectures
<a name="eos-architecture-comparison-alarms"></a>

The current Amazon IoT Events alarm configuration for Amazon IoT SiteWise properties requires creating `AssetModelCompositeModels` in the asset model, as described in [Define external alarms in Amazon IoT SiteWise](https://docs.amazonaws.cn/iot-sitewise/latest/userguide/define-external-alarms.html) in the *Amazon IoT SiteWise User Guide*. Modifications to the new solution are typically managed through the Amazon IoT Events console.

The new solution provides alarm management by leveraging CloudWatch alarms. This approach uses Amazon IoT SiteWise notifications to publish property data points to Amazon IoT Core MQTT topics, which are then processed by a Lambda function. The function transforms these notifications into CloudWatch metrics, enabling alarm monitoring through CloudWatch's alarming framework.


| Purpose | Solution | Differences | 
| --- | --- | --- | 
| **Data source** – Property data from Amazon IoT SiteWise | Amazon IoT SiteWise MQTT notifications | Replaces direct IoT Events integration with MQTT notifications from Amazon IoT SiteWise properties | 
| **Data processing** – Transforms property data | Lambda function | Processes Amazon IoT SiteWise property notifications and converts them to CloudWatch metrics | 
| **Alarm evaluation** – Monitors metrics and triggers alarms | Amazon CloudWatch alarms | Replaces Amazon IoT Events alarms with CloudWatch alarms, offering additional features like anomaly detection | 
| **Integration** – Connection with Amazon IoT SiteWise | Amazon IoT SiteWise external alarms | Optional capability to import CloudWatch alarms back into Amazon IoT SiteWise as external alarms | 

## Step 1: Enable MQTT notifications on the asset property
<a name="eos-alarms-mqtt-asset-property"></a>

If you are using Amazon IoT Events integrations for Amazon IoT SiteWise alarms, you can turn on MQTT notifications for each property to monitor.

1. Follow the [Configure alarms on assets in Amazon IoT SiteWise](https://docs.amazonaws.cn/iot-sitewise/latest/userguide/configure-alarms.html#configure-alarm-threshold-value-console) procedure until you each the step to **Edit** the asset model's properties.

1. For each property to migrate, change the **MQTT Notification status** to **ACTIVE**.  
![A screenshot showing the placement of the MQTT notification status dropdown in the Amazon IoT SiteWise console.](http://docs.amazonaws.cn/en_us/iotevents/latest/developerguide/images/events-eos-sw-asset-mqtt.png)

1. Note the topic path to which the alarm publishes for each modified alarm attribute.

For more information, see the following documentation resources:
+ [Understand asset properties in MQTT topics](https://docs.amazonaws.cn/iot-sitewise/latest/userguide/mqtt-topics.html) in the *Amazon IoT SiteWise User Guide*.
+ [MQTT topics](https://docs.amazonaws.cn/iot/latest/developerguide/topics.html) in the *Amazon IoT Developer Guide*.

## Step 2: Create an Amazon Lambda function
<a name="eos-alarms-lambda-function"></a>

Create an Lambda function for reading the TQV array published by the MQTT topic and publish individual values to CloudWatch. We’ll use this Lambda function as a destination action to trigger in Amazon IoT Core Message Rules.

1. Open the [Amazon Lambda console](https://console.amazonaws.cn/lambda).

1. Choose **Create function**.

1. Enter a name for the **Function name**.

1. Select **NodeJS 22.x** as the **Runtime**.

1. In the **Change default execution role** dropdown, choose **Use existing role**, and then select the IAM role that you created in earlier steps.
**Note**  
This procedure assumes that you've already migrated your detector model. If you don't have an IAM role, see [Step 2: Create an IAM role](eos-procedure-detector-models.md#eos-detector-model-create-iam-role).

1. Choose **Create function**.

1. Paste in the following code snippet after replacing the hard coded constants.

   ```
   import json
   import boto3
   from datetime import datetime
   
   # Initialize CloudWatch client
   cloudwatch = boto3.client('cloudwatch')
   
   def lambda_handler(message, context):
       try:
           # Parse the incoming IoT message
           # Extract relevant information
           asset_id = message['payload']['assetId']
           property_id = message['payload']['propertyId']
           
           # Process each value in the values array
           for value in message['payload']['values']:
               # Extract timestamp and value
               timestamp = datetime.fromtimestamp(value['timestamp']['timeInSeconds'])
               metric_value = value['value']['doubleValue']
               quality = value.get('quality', 'UNKNOWN')
               
               # Publish to CloudWatch
               response = cloudwatch.put_metric_data(
                   Namespace='{{IoTSiteWise/AssetMetrics}}',
                   MetricData=[
                       {
                           'MetricName': f'Property_{{your-property-id}}',
                           'Value': metric_value,
                           'Timestamp': timestamp,
                           'Dimensions': [
                               {
                                   'Name': 'AssetId',
                                   'Value': '{{your-asset-id}}'
                               },
                               {
                                   'Name': 'Quality',
                                   'Value': quality
                               }
                           ]
                       }
                   ]
               )
               
           return {
               'statusCode': 200,
               'body': json.dumps('Successfully published metrics to CloudWatch')
           }
           
       except Exception as e:
           print(f'Error processing message: {str(e)}')
           return {
               'statusCode': 500,
               'body': json.dumps(f'Error: {str(e)}')
           }
   ```

## Step 3: Create Amazon IoT Core message routing rule
<a name="eos-alarms-message-routing"></a>
+ Follow the [Tutorial: Republishing an MQTT message](https://docs.amazonaws.cn/iot/latest/developerguide/iot-repub-rule.html) procedure entering the following information when prompted:

  1. Name message routing rule `SiteWiseToCloudwatchAlarms`.

  1. For the query, you can use the following:

     ```
     SELECT * FROM '$aws/sitewise/asset-models/{{your-asset-model-id}}/assets/{{your-asset-id}}/properties/{{your-property-id}}'
     ```

  1. In **Rule actions**, select the **Lambda** action to send the data generated from Amazon IoT SiteWise to CloudWatch. For example:  
![A screenshot showing the rule action for the Lambda function.](http://docs.amazonaws.cn/en_us/iotevents/latest/developerguide/images/events-eos-lambda-rule-action.png)

## Step 4: View CloudWatch metrics
<a name="eos-alarms-metrics"></a>

As you ingest data to Amazon IoT SiteWise, the property selected earlier in [Step 1: Enable MQTT notifications on the asset property](#eos-alarms-mqtt-asset-property), the routes data to the Lambda function we created in [Step 2: Create an Amazon Lambda function](#eos-alarms-lambda-function). In this step, you can check to see the Lambda sending your metrics to CloudWatch.

1. Open the [CloudWatch Amazon Web Services Management Console](https://console.amazonaws.cn/cloudwatch/).

1. In the left navigation, choose **Metrics**, then **All metrics**.

1. Choose an alarm's URL to open it.

1. Under the **Source** tab, the CloudWatch output looks similar to this example. This source information confirms that the metric data is feeding into CloudWatch.

   ```
   {
       "view": "timeSeries",
       "stacked": false,
       "metrics": [
           [ "IoTSiteWise/AssetMetrics", "Property_your-property-id-hash", "Quality", "GOOD", "AssetId", "your-asset-id-hash", { "id": "m1" } ]
       ],
       "region": "your-region"
   }
   ```

## Step 5: Create CloudWatch alarms
<a name="eos-create-cw-alarm"></a>

Follow the [Create a CloudWatch alarm based on a static threshold](https://docs.amazonaws.cn/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html) procedure in the *Amazon CloudWatch User Guide* to create alarms for each relevant metric.

**Note**  
There are many options for alarm configuration in Amazon CloudWatch For more information on CloudWatch alarms, see [Using Amazon CloudWatch alarms](https://docs.amazonaws.cn/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html) in the *Amazon CloudWatch User Guide*.

## Step 6: (Optional) import the CloudWatch alarm into Amazon IoT SiteWise
<a name="eos-import-cw-alarm-sw"></a>

You can configure CloudWatch alarms to send data back to Amazon IoT SiteWise using CloudWatch alarm actions and Lambda. This integration enables you to view alarm states and properties in the SiteWise Monitor portal.

1. Configure the external alarm as a property in an asset model. For more information, see [Define external alarms in Amazon IoT SiteWise](https://docs.amazonaws.cn/iot-sitewise/latest/userguide/define-external-alarms.html) in the *Amazon IoT SiteWise User Guide*.

1. Create a Lambda function that uses the [BatchPutAssetPropertyValue](https://docs.amazonaws.cn/iot-sitewise/latest/APIReference/API_BatchPutAssetPropertyValue.html) API found in the *Amazon IoT SiteWise User Guide* to send alarm data to Amazon IoT SiteWise.

1. Set up CloudWatch alarm actions to invoke your Lambda function when alarm states change. For more information, see the [Alarm actions](https://docs.amazonaws.cn/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html#alarms-and-actions.html) section in the *Amazon CloudWatch User Guide*.