Storing analytics data
The Amazon Kinesis Firehose analytics provider allows you to send analytics data to an Amazon Kinesis Firehose stream for reliably storing data.
Installation and Configuration
Register the AWSKinesisFirehoseProvider with the Analytics category:
1import { Analytics, AWSKinesisFirehoseProvider } from 'aws-amplify';2Analytics.addPluggable(new AWSKinesisFirehoseProvider());
Ensure you have setup IAM permissions for PutRecordBatch
.
Example IAM policy for Amazon Kinesis Firehose:
1{2 "Version": "2012-10-17",3 "Statement": [4 {5 "Effect": "Allow",6 "Action": ["firehose:PutRecord", "firehose:PutRecordBatch"],7 "Resource": "*"8 }9 ]10}
Configure Kinesis Firehose:
1// Configure the plugin after adding it to the Analytics module2Analytics.configure({3 AWSKinesisFirehose: {4 // OPTIONAL - Amazon Kinesis Firehose service region5 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, // 5s15
16 // OPTIONAL - The limit for failed recording retries.17 resendLimit: 518 }19});
Storing data
You can send a data to a Kinesis Firehose stream with the standard record
method. Any data is acceptable and streamName
is required:
1Analytics.record(2 {3 data: {4 // The data blob to put into the record5 },6 streamName: 'myKinesisStream'7 },8 'AWSKinesisFirehose'9);