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:

import { Analytics, AWSKinesisProvider } from 'aws-amplify'; Analytics.addPluggable(new AWSKinesisProvider());
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:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["kinesis:PutRecord", "kinesis:PutRecords"], "Resource": "*" } ] }
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:

// Configure the plugin after adding it to the Analytics module Analytics.configure({ AWSKinesis: { // OPTIONAL - Amazon Kinesis service region region: 'XX-XXXX-X', // OPTIONAL - The buffer size for events in number of items. bufferSize: 1000, // OPTIONAL - The number of events to be deleted from the buffer when flushed. flushSize: 100, // OPTIONAL - The interval in milliseconds to perform a buffer check and flush if necessary. flushInterval: 5000, // 5s // OPTIONAL - The limit for failed recording retries. resendLimit: 5 } });
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:

Analytics.record( { data: { // The data blob to put into the record }, // OPTIONAL partitionKey: 'myPartitionKey', streamName: 'myKinesisStream' }, 'AWSKinesis' );
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);