Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Apr 29, 2024

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

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

Example IAM policy for Amazon Kinesis:

{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": "kinesis:PutRecords",
"Resource": "arn:aws:kinesis:<Region>:<AccountId>:stream/<StreamName>" // replace the template fields
}]
}

For more information visit Amazon Kinesis Developer Documentation.

Configure Kinesis:

// Configure the plugin after adding it to the Analytics module
import { Amplify } from 'aws-amplify';
import { parseAmplifyConfig } from "aws-amplify/utils";
import amplifyconfig from './amplifyconfiguration.json';
Amplify.configure({
...parseAmplifyConfig(amplifyconfig),
Analytics: {
Kinesis: {
// REQUIRED - Amazon Kinesis service region
region: 'us-east-1',
// 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
}
}
});

Stream data

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

import { record } from 'aws-amplify/analytics/kinesis';
record({
data: {
// The data blob to put into the record
},
partitionKey: 'myPartitionKey',
streamName: 'myKinesisStream'
});

Flush events

The recorded events are saved in a buffer and sent to the remote server periodically (You can tune it with the flushInterval option). If needed, you have the option to manually clear all the events from the buffer by using the 'flushEvents' API.

import { flushEvents } from 'aws-amplify/analytics/kinesis';
flushEvents();