AWS SDK for PHP
Developer Guide

Manage Data Shards Using the Kinesis Data Streams API and the AWS SDK for PHP Version 3

Amazon Kinesis Data Streams enables you to send real-time data to an endpoint. The rate of data flow depends on the number of shards in your stream.

You can write 1,000 records per second to a single shard. Each shard also has an upload limit of 1 MiB per second. Usage is calculated and charged on a per-shard basis, so use these examples to manage the data capacity and cost of your stream.

The following examples show how to:

All the example code for the AWS SDK for PHP Version 3 is available here on GitHub.

Credentials

Before running the example code, configure your AWS credentials, as described in Credentials for the AWS SDK for PHP Version 3. Then import the AWS SDK for PHP, as described in Basic Usage Patterns of the AWS SDK for PHP Version 3.

For more information about using Amazon Kinesis Data Streams, see the Amazon Kinesis Data Streams Developer Guide.

List Data Stream Shards

List the details of up to 100 shards in a specific stream.

To list the shards in a Kinesis data stream, use the ListShards operation.

Imports

require 'vendor/autoload.php'; use Aws\Kinesis\KinesisClient; use Aws\Exception\AwsException;

Sample Code

$kinesisClient = new Aws\Kinesis\KinesisClient([ 'profile' => 'default', 'version' => '2013-12-02', 'region' => 'us-east-2' ]); $name = "my_stream_name"; try { $result = $kinesisClient->ListShards([ 'StreamName' => $name, ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }

Add More Data Stream Shards

If you need more data stream shards, you can increase your current number of shards. We recommend that you double your shard count when increasing. This makes a copy of each shard currently available to increase your capacity. You can double the number of your shards only twice in one 24-hour period.

Remember that billing for Kinesis Data Streams usage is calculated per shard, so when demand decreases, we recommend that you reduce your shard count by half. When you remove shards, you can only scale down the amount of shards to half of your current shard count.

To update the shard count of a Kinesis data stream, use the UpdateShardCount operation.

Imports

require 'vendor/autoload.php'; use Aws\Kinesis\KinesisClient; use Aws\Exception\AwsException;

Sample Code

$kinesisClient = new Aws\Kinesis\KinesisClient([ 'profile' => 'default', 'version' => '2013-12-02', 'region' => 'us-east-2' ]); $name = "my_stream_name"; $totalshards = 4; try { $result = $kinesisClient->UpdateShardCount([ 'ScalingType' => 'UNIFORM_SCALING', 'StreamName' => $name, 'TargetShardCount' => $totalshards ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }