Skip to content

Instantly share code, notes, and snippets.

@vladaman
Created April 8, 2014 17:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladaman/10159707 to your computer and use it in GitHub Desktop.
Save vladaman/10159707 to your computer and use it in GitHub Desktop.
PHP Code to request Temporary Amazon AMI Credentials and publish message dummy message to Kinesis Service
<?php
require 'aws-autoloader.php';
use Aws\Sts\StsClient;
use Aws\Kinesis\KinesisClient;
// In real applications, the following code is part of your trusted code.
// It has your security credentials that you use to obtain temporary
// security credentials.
$sts = StsClient::factory(array(
'key' => 'ACCESS-KEY-HERE',
'secret' => 'SECRET-KEY-HERE'
));
$duration = 129600;
$duration = 3600;
// Get Session Tokens
$result = $sts->getSessionToken(array(
'DurationSeconds' => $duration
));
// Get Credentials
$credentials = $result->get('Credentials');
$cr = array(
'Key' => $credentials['AccessKeyId'],
'Secret' => $credentials['SecretAccessKey'],
'Token' => $credentials['SessionToken'],
'Expires' => $credentials['Expiration'],
'StreamName' => 'sink-name',
'Region' => 'us-east-1'
);
// Encode JSON Object
print_r(json_encode($cr,JSON_FORCE_OBJECT));
// Kinesis
$client = KinesisClient::factory(array(
'key' => $cr['Key'],
'secret' => $cr['Secret'],
'token' => $cr['Token'],
'region' => $cr['Region']
));
$data = array('me'=>'you');
$result = $client->putRecord(array(
// StreamName is required
'StreamName' => $cr['StreamName'],
// The supplied string value will be automatically base64 encoded by the SDK
'Data' => json_encode($data),
'PartitionKey' => 'part-key'
));
print_r($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment