Page updated Nov 9, 2023

Streaming analytics data

The Amazon Kinesis analytics provider allows you to send analytics data to an Amazon Kinesis stream for real-time processing.

Installation and Configuration

Register the AWSKinesisProvider with the Analytics category:

1import { Analytics, AWSKinesisProvider } from 'aws-amplify';
2Analytics.addPluggable(new AWSKinesisProvider());

If you did not use the CLI, ensure you have setup IAM permissions for PutRecords.

Example IAM policy for Amazon Kinesis:

1{
2 "Version": "2012-10-17",
3 "Statement": [
4 {
5 "Effect": "Allow",
6 "Action": ["kinesis:PutRecord", "kinesis:PutRecords"],
7 "Resource": "*"
8 }
9 ]
10}

For more information visit Amazon Kinesis Developer Documentation.

Configure Kinesis:

1// Configure the plugin after adding it to the Analytics module
2Analytics.configure({
3 AWSKinesis: {
4 // OPTIONAL - Amazon Kinesis service region
5 region: 'XX-XXXX-X',
6
7 // OPTIONAL - The buffer size for events in number of items.
8 bufferSize: 1000,
9
10 // OPTIONAL - The number of events to be deleted from the buffer when flushed.
11 flushSize: 100,
12
13 // OPTIONAL - The interval in milliseconds to perform a buffer check and flush if necessary.
14 flushInterval: 5000, // 5s
15
16 // OPTIONAL - The limit for failed recording retries.
17 resendLimit: 5
18 }
19});

Stream data

You can send a data to a Kinesis stream with the standard record() method:

1Analytics.record(
2 {
3 data: {
4 // The data blob to put into the record
5 },
6 // OPTIONAL
7 partitionKey: 'myPartitionKey',
8 streamName: 'myKinesisStream'
9 },
10 'AWSKinesis'
11);