Last active
August 29, 2015 14:18
-
-
Save masayuki5160/a6bd8c46a286203e42e7 to your computer and use it in GitHub Desktop.
AWS Kinesisを使うまで
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require":{ | |
"aws/aws-sdk-php":"2.*" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require './vendor/autoload.php'; | |
use Aws\Kinesis\KinesisClient; | |
use Aws\Common\Enum\Region; | |
$kinesis = KinesisClient::factory(array( | |
'key' => 'IAMで取得したキー名', | |
'secret' => 'IAMで取得したシークレットキー名', | |
'region' => Region::TOKYO // streamを作成したリージョン | |
)); | |
$shard_iterator_info = $kinesis->getShardIterator(array( | |
'StreamName' => 'masayuki', | |
'ShardId' => 'shardId-000000000000', | |
'ShardIteratorType' => 'TRIM_HORIZON', | |
)); | |
$shard_iterator = null; | |
while (true) { | |
if (is_null($shard_iterator)) { | |
$shard_iterator = $shard_iterator_info['ShardIterator']; | |
} else { | |
$shard_iterator = $records_info['NextShardIterator']; | |
} | |
$records_info = $kinesis->getRecords(array( | |
'ShardIterator' => $shard_iterator, | |
'Limit' => 100 | |
)); | |
$records = $records_info['Records']; | |
if (!empty($records)) { | |
// Recordsは必ずしも取れるわけではない | |
var_dump($records); | |
} | |
sleep(1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWS SDKインストール(EC2上で実施) | |
[参考]AWS SDK編~for PHP~ | |
http://recipe.kc-cloud.jp/archives/6045 | |
# sudo yum update | |
# sudo yum install php | |
# curl -sS https://getcomposer.org/installer | php | |
# vim composer.json | |
# php composer.phar install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require './vendor/autoload.php'; | |
use Aws\Kinesis\KinesisClient; | |
use Aws\Common\Enum\Region; | |
$kinesis = KinesisClient::factory(array( | |
'key' => 'IAMで取得したキー名', | |
'secret' => 'IAMで取得したシークレットキー名', | |
'region' => Region::TOKYO // streamを作成したリージョン | |
)); | |
while (true) { | |
$sample_data = date('YmdHis'); | |
//=============================// | |
// Kinesiへのデータ送信処理 | |
//=============================// | |
$result = $kinesis->putRecord(array( | |
'StreamName' => 'masayuki',// stream名を設定 | |
'Data' => $sample_data, | |
'PartitionKey' => 'kinesis-sample' | |
)); | |
echo "put data:$sample_data" . PHP_EOL; | |
sleep(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[参考サイト]
AWS SDK編~for PHP~
http://recipe.kc-cloud.jp/archives/6045
awsのs3を操作する為のaccess keyとsecret keyを取得する(IAM)
http://joppot.info/2014/06/14/1621
AWS SDK for PHP 2を利用してAmazon Kinesisを操作してみた
http://f-retu.hatenablog.com/entry/2014/02/23/231434