

# Streaming messaging data in Amazon Chime SDK messaging
Streaming messaging data

You can configure an `AppInstance` to receive data, such as messages and channel events, in the form of a stream. You can then react to that data in real time. Currently, Amazon Chime SDK messaging only accepts Kinesis streams as stream destinations. You must have these prerequisites to use Kinesis streams with this feature:
+ Kinesis streams must be in the same AWS account as the `AppInstance`.
+ A stream must be in the same region as the `AppInstance`.
+ Stream names have a prefix that starts with `chime-messaging-`.
+ You must configure at least two shards. Each shard can receive data up to 1MB per second, so scale your stream accordingly.
+ You must enable server-side encryption (SSE).

**To configure a Kinesis stream**

1. Create one or more Kinesis streams using the prerequisites in the previous section, then get the ARN. Ensure the caller has Kinesis permissions in addition to Amazon Chime permissions.

   The following examples show how to use the AWS CLI to create a Kinesis stream with two shards, and how to enable SSE.

   `aws kinesis create-stream --stream-name chime-messaging-unique-name --shard-count 2`

   `aws kinesis start-stream-encryption --stream-name chime-messaging-unique-name --encryption-type KMS --key-id "alias/aws/kinesis"`

1. Configure streaming by calling the [https://docs.aws.amazon.com/chime-sdk/latest/APIReference/API_messaging-chime_PutMessagingStreamingConfigurations.html](https://docs.aws.amazon.com/chime-sdk/latest/APIReference/API_messaging-chime_PutMessagingStreamingConfigurations.html) API.

   You can configure one or both of two data types, and you can choose the same stream or separate streams for them.

   The following examples show how to use the AWS CLI to configure an `appinstance` to stream the `ChannelMessage` and `Channel` data types.

   ```
   aws chime-sdk-messaging put-messaging-streaming-configurations --app-instance-arn app_instance_arn \
   --streaming-configurations DataType=ChannelMessage,ResourceArn=kinesis_data_stream_arn
   ```

   ```
   aws chime-sdk-messaging put-messaging-streaming-configurations --app-instance-arn app_instance_arn \
   --streaming-configurations DataType=Channel,ResourceArn=kinesis_data_stream_arn
   ```

   The data types have the following scopes:    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/chime-sdk/latest/dg/streaming-export.html)

1. Start reading the data from your configured Kinesis stream.
**Note**  
Any events sent before you configure streaming are not sent to your Kinesis stream.

**Data format**  
Kinesis outputs records in JSON format with the following fields: `EventType` and `Payload`. The payload format depends on the `EventType`. The following table lists the event types and their corresponding payload formats.

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/chime-sdk/latest/dg/streaming-export.html)