AWS SDK for PHP
Developer Guide

Creating Delivery Streams Using the Kinesis Data Firehose API and the AWS SDK for PHP Version 3

Amazon Kinesis Data Firehose enables you to send real-time data to other AWS services including Amazon Kinesis Data Streams, Amazon S3, Amazon Elasticsearch Service (Amazon ES), and Amazon Redshift, or to Splunk. Create a data producer with delivery streams to deliver data to the configured destination every time you add data.

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 Firehose, see the Amazon Kinesis Data Firehose Developer Guide.

Create a Delivery Stream Using a Kinesis Data Stream

To establish a delivery stream that puts data into an existing Kinesis data stream, use the CreateDeliveryStream operation.

This enables developers to migrate existing Kinesis services to Kinesis Data Firehose.

Imports

require 'vendor/autoload.php'; use Aws\Firehose\FirehoseClient; use Aws\Exception\AwsException;

Sample Code

$firehoseClient = new Aws\Firehose\FirehoseClient([ 'profile' => 'default', 'version' => '2015-08-04', 'region' => 'us-east-2' ]); $name = "my_stream_name"; $stream_type = "KinesisStreamAsSource"; $kinesis_stream = "arn:aws:kinesis:us-east-2:0123456789:stream/my_stream_name"; $role = "arn:aws:iam::0123456789:policy/Role"; try { $result = $firehoseClient->createDeliveryStream([ 'DeliveryStreamName' => $name, 'DeliveryStreamType' => $stream_type, 'KinesisStreamSourceConfiguration' => [ 'KinesisStreamARN' => $kinesis_stream, 'RoleARN' => $role, ], ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }

Create a Delivery Stream Using an Amazon S3 Bucket

To establish a delivery stream that puts data into an existing Amazon S3 bucket, use the CreateDeliveryStream operation.

Provide the destination parameters, as described in Destination Parameters. Then ensure that you grant Kinesis Data Firehose access to your Amazon S3 bucket, as described in Grant Kinesis Data Firehose Access to an Amazon S3 Destination.

Imports

require 'vendor/autoload.php'; use Aws\Firehose\FirehoseClient; use Aws\Exception\AwsException;

Sample Code

$firehoseClient = new Aws\Firehose\FirehoseClient([ 'profile' => 'default', 'version' => '2015-08-04', 'region' => 'us-east-2' ]); $name = "my_S3_stream_name"; $stream_type = "DirectPut"; $s3bucket = 'arn:aws:s3:::bucket_name'; $s3Role = 'arn:aws:iam::0123456789:policy/Role'; try { $result = $firehoseClient->createDeliveryStream([ 'DeliveryStreamName' => $name, 'DeliveryStreamType' => $stream_type, 'S3DestinationConfiguration' => [ 'BucketARN' => $s3bucket, 'CloudWatchLoggingOptions' => [ 'Enabled' => false, ], 'RoleARN' => $s3Role ], ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }

Create a Delivery Stream Using Amazon ES

To establish a Kinesis Data Firehose delivery stream that puts data into an Amazon ES cluster, use the CreateDeliveryStream operation.

Provide the destination parameters, as described in Destination Parameters. Ensure that you grant Kinesis Data Firehose access to your Amazon ES cluster, as described in Grant Kinesis Data Firehose Access to an Amazon ES Destination.

Imports

require 'vendor/autoload.php'; use Aws\Firehose\FirehoseClient; use Aws\Exception\AwsException;

Sample Code

$firehoseClient = new Aws\Firehose\FirehoseClient([ 'profile' => 'default', 'version' => '2015-08-04', 'region' => 'us-east-2' ]); $name = "my_ES_stream_name"; $stream_type = "DirectPut"; $esDomainARN = 'arn:aws:es:us-east-2:0123456789:domain/Name'; $esRole = 'arn:aws:iam::0123456789:policy/Role'; $esIndex = 'root'; $esType = 'PHP_SDK'; $s3bucket = 'arn:aws:s3:::bucket_name'; $s3Role = 'arn:aws:iam::0123456789:policy/Role'; try { $result = $firehoseClient->createDeliveryStream([ 'DeliveryStreamName' => $name, 'DeliveryStreamType' => $stream_type, 'ElasticsearchDestinationConfiguration' => [ 'DomainARN' => $esDomainARN, 'IndexName' => $esIndex, 'RoleARN' => $esRole, 'S3Configuration' => [ 'BucketARN' => $s3bucket, 'CloudWatchLoggingOptions' => [ 'Enabled' => false, ], 'RoleARN' => $s3Role, ], 'TypeName' => $esType, ], ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }

Retrieve a Delivery Stream

To get the details about an existing Kinesis Data Firehose delivery stream, use the DescribeDeliveryStream operation.

Imports

require 'vendor/autoload.php'; use Aws\Firehose\FirehoseClient; use Aws\Exception\AwsException;

Sample Code

$firehoseClient = new Aws\Firehose\FirehoseClient([ 'profile' => 'default', 'version' => '2015-08-04', 'region' => 'us-east-2' ]); $name = "my_stream_name"; try { $result = $firehoseClient->describeDeliveryStream([ 'DeliveryStreamName' => $name, ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }

List Existing Delivery Streams Connected to Kinesis Data Streams

To list all the existing Kinesis Data Firehose delivery streams sending data to Kinesis Data Streams, use the ListDeliveryStreams operation.

Imports

require 'vendor/autoload.php'; use Aws\Firehose\FirehoseClient; use Aws\Exception\AwsException;

Sample Code

$firehoseClient = new Aws\Firehose\FirehoseClient([ 'profile' => 'default', 'version' => '2015-08-04', 'region' => 'us-east-2' ]); try { $result = $firehoseClient->listDeliveryStreams([ 'DeliveryStreamType' => 'KinesisStreamAsSource', ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }

List Existing Delivery Streams Sending Data to Other AWS Services

To list all the existing Kinesis Data Firehose delivery streams sending data to Amazon S3, Amazon ES, or Amazon Redshift, or to Splunk, use the ListDeliveryStreams operation.

Imports

require 'vendor/autoload.php'; use Aws\Firehose\FirehoseClient; use Aws\Exception\AwsException;

Sample Code

$firehoseClient = new Aws\Firehose\FirehoseClient([ 'profile' => 'default', 'version' => '2015-08-04', 'region' => 'us-east-2' ]); try { $result = $firehoseClient->listDeliveryStreams([ 'DeliveryStreamType' => 'DirectPut', ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }

Send Data to an Existing Kinesis Data Firehose Delivery Stream

To send data through a Kinesis Data Firehose delivery stream to your specified destination, use the PutRecord operation after you create a Kinesis Data Firehose delivery stream.

Before sending data to a Kinesis Data Firehose delivery stream, use DescribeDeliveryStream to see if the delivery stream is active.

Imports

require 'vendor/autoload.php'; use Aws\Firehose\FirehoseClient; use Aws\Exception\AwsException;

Sample Code

$firehoseClient = new Aws\Firehose\FirehoseClient([ 'profile' => 'default', 'version' => '2015-08-04', 'region' => 'us-east-2' ]); $name = "my_stream_name"; $content = '{"ticker_symbol":"QXZ", "sector":"HEALTHCARE", "change":-0.05, "price":84.51}'; try { $result = $firehoseClient->putRecord([ 'DeliveryStreamName' => $name, 'Record' => [ 'Data' => $content, ], ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }

Delete a Kinesis Data Firehose Delivery Stream

To delete a Kinesis Data Firehose delivery stream, use the DeleteDeliveryStreams operation. This also deletes any data you have sent to the delivery stream.

Imports

require 'vendor/autoload.php'; use Aws\Firehose\FirehoseClient; use Aws\Exception\AwsException;

Sample Code

$firehoseClient = new Aws\Firehose\FirehoseClient([ 'profile' => 'default', 'version' => '2015-08-04', 'region' => 'us-east-2' ]); $name = "my_stream_name"; try { $result = $firehoseClient->deleteDeliveryStream([ 'DeliveryStreamName' => $name, ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }