This document describes the example applications provided with the AWSKinesisStreams library:
- DataProducer, which writes data records to an AWS Kinesis Stream.
- DataConsumer, which reads data records from an AWS Kinesis Stream.
To read data you need to run DataConsumer in parallel with DataProducer. We recommend that you run DataProducer as the agent of one imp and run DataConsumer as the agent of a second imp.
Each example is described below. If you wish to try one out, you will find setup instructions further down the page.
IMPORTANT Before proceeding, please review Amazon Kinesis Streams Pricing. Running these examples may not be free of charge.
This example writes data records to the specified preconfigured AWS Kinesis Stream:.
- Data records are written every ten seconds.
- Data records are written using the putRecord() and putRecords() methods of AWSKinesisStreams.Producer, switching the method every ten seconds.
- Every data record contains:
- A
"value"
attribute. This is an integer value which starts at 1 and increases by 1 with every record written. It restarts from 1 every time the example is restarted. - An
"origin"
attribute. This contains the name of the method used to write the record, ie."putRecord"
or"putRecords"
.
- A
This example reads new data records from all shards of the specified preconfigured AWS Kinesis Stream.
- Only new records, appeared in the AWS Kinesis Streams after the example is started, are read.
- The first read occurs 15 seconds after the example is started.
- After that, data records are read every 15 seconds.
- Every received data record is printed to the log.
- In the Electric Imp IDE create two new models, one for imp A and the other for imp B.
- Copy the DataProducer source code and paste it into the IDE as agent code for imp A.
- Copy the DataConsumer source code and paste it into the IDE as agent code for imp B.
- Perform AWS Kinesis Streams Setup as described below.
- Perform Agent Constants Setup as described below.
- Build and Run DataProducer.
- Check from the logs in the IDE that data is being written successfully.
- Build and Run DataConsumer.
- Check from the logs in the IDE that data is being read successfully.
This process assumes you have an AWS account and are signed in to AWS in your web browser.
IMPORTANT Before proceeding, please review Amazon Kinesis Streams Pricing. Running these examples may not be free of charge.
- Open the Amazon Kinesis console in your web browser.
- Click Go to the Streams console:
- Click Create Kinesis stream:
- Enter
testStream
into the Kinesis stream name field. - Enter
1
into the Number of shards field. - Click Create Kinesis stream:
- You will be redirected to the Kinesis streams list page.
- Wait until the status of your Stream is changed to ACTIVE.
- Click to your Stream name:
- Copy the Stream ARN of your Stream and paste it into a text document or equivalent for use later:
- The ARN format is
arn:aws:kinesis:region:account:stream/name
. Copy the region, eg.us-east-2
and paste it into a text document or equivalent. It will be used as the value of the AWS_KINESIS_REGION constant in the agent code.
- Open the AWS IAM console in your web browser.
- Click Policies in the left-hand menu:
- Click Create policy:
- Under Policy Generator, click Select:
- Choose Amazon Kinesis as the AWS service.
- Choose All Actions in the Actions field:
- Enter your Stream ARN, which you retrieved above, in the Amazon Resource Name (ARN) field.
- Click Add Statement:
- Click Next Step:
- Change Policy Name to
testStreamPolicy
. - Click Create Policy:
- Click Users in the left-hand menu.
- Click Add user:
- Enter
testStreamUser
in the User name field. - For Access type choose Programmatic access.
- Click Next: Permissions:
- Click Attach existing policies directly:
- In the Search field enter
testStreamPolicy
. - Check the box to the left of your policy name.
- Click Next: Review:
- Click Create user:
- Copy the Access key ID and paste it onto a text document or equivalent. It will be used as the value of the AWS_KINESIS_ACCESS_KEY_ID constant in the agent code.
- Click Show under Secret access key. Copy the Secret access key and paste it onto a text document or equivalent. It will be used as the value of the AWS_KINESIS_SECRET_ACCESS_KEY constant in the agent code: