

# Amazon IoT Events
<a name="iotevents-rule-action"></a>

The Amazon IoT Events (`iotEvents`) action sends data from an MQTT message to an Amazon IoT Events input. 

**Important**  
If the payload is sent to Amazon IoT Core without the `Input attribute Key`, or if the key isn't in the same JSON path specified in the key, it will cause the IoT rule to fail with the error `Failed to send message to Iot Events`.

## Requirements
<a name="iotevents-rule-action-requirements"></a>

This rule action has the following requirements:
+ An IAM role that Amazon IoT can assume to perform the `iotevents:BatchPutMessage` operation. For more information, see [Granting an Amazon IoT rule the access it requires](iot-create-role.md).

  In the Amazon IoT console, you can choose or create a role to allow Amazon IoT to perform this rule action.

## Parameters
<a name="iotevents-rule-action-parameters"></a>

When you create an Amazon IoT rule with this action, you must specify the following information:

`batchMode`  
(Optional) Whether to process the event actions as a batch. The default value is `false`.  
When `batchMode` is `true` and the rule SQL statement evaluates to an Array, each Array element is treated as a separate message when it's sent to Amazon IoT Events by calling [https://docs.aws.amazon.com/iotevents/latest/apireference/API_iotevents-data_BatchPutMessage.html](https://docs.aws.amazon.com/iotevents/latest/apireference/API_iotevents-data_BatchPutMessage.html). The resulting array can't have more than 10 messages.  
When `batchMode` is `true`, you can't specify a `messageId`.   
Supports [substitution templates](iot-substitution-templates.md): No

`inputName`  
The name of the Amazon IoT Events input.  
Supports [substitution templates](iot-substitution-templates.md): API and Amazon CLI only

`messageId`  
(Optional) Use this to verify that only one input (message) with a given `messageId` is processed by an Amazon IoT Events detector. You can use the `${newuuid()}` substitution template to generate a unique ID for each request.  
When `batchMode` is `true`, you can't specify a `messageId`--a new UUID value will be assigned.  
Supports [substitution templates](iot-substitution-templates.md): Yes

`roleArn`  
The IAM role that allows Amazon IoT to send an input to an Amazon IoT Events detector. For more information, see [Requirements](#iotevents-rule-action-requirements).  
Supports [substitution templates](iot-substitution-templates.md): No

## Examples
<a name="iotevents-rule-action-examples"></a>

The following JSON example defines an IoT Events action in an Amazon IoT rule.

```
{
    "topicRulePayload": {
        "sql": "SELECT * FROM 'some/topic",
        "ruleDisabled": false,
        "awsIotSqlVersion": "2016-03-23",
        "actions": [
            {
                "iotEvents": {
                    "inputName": "MyIoTEventsInput",
                    "messageId": "${newuuid()}",
                    "roleArn": "arn:aws:iam::123456789012:role/aws_iot_events"
                }
            }
        ]
    }
}
```

## See also
<a name="iotevents-rule-action-see-also"></a>
+ [What is Amazon IoT Events?](https://docs.amazonaws.cn/iotevents/latest/developerguide/) in the *Amazon IoT Events Developer Guide*