本文整理汇总了PHP中Aws\DynamoDb\DynamoDbClient类的典型用法代码示例。如果您正苦于以下问题:PHP DynamoDbClient类的具体用法?PHP DynamoDbClient怎么用?PHP DynamoDbClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DynamoDbClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
* Initialize the dynamodb client.
*/
public function init()
{
parent::init();
//For v2 compatibility.
//TODO: remove deprecated.
$this->_client = DynamoDbClient::factory($this->config);
}
示例2: init
/**
* Initialize the client.
*/
public function init()
{
$this->_client = DynamoDbClient::factory($this->config);
if ($this->keyPrefix === null) {
$this->keyPrefix = substr(md5(Yii::$app->id), 0, 5);
}
parent::init();
}
示例3: __construct
public function __construct($region = false)
{
if (!$region && !($region = getenv("AWS_DEFAULT_REGION"))) {
throw new \Exception("Set 'AWS_DEFAULT_REGION' environment variable!");
}
$this->region = $region;
$this->sns = SnsClient::factory(['region' => $region]);
$this->ddb = DynamoDbClient::factory(['region' => $region]);
}
示例4: testRemoveAKey
public function testRemoveAKey()
{
// Arrange.
$key = 'bar';
$this->mockDynamoDbClient->expects($this->once())->method('deleteItem')->with(['TableName' => $this->storeKeyTableName, 'Key' => [$this->storeKeyAttribute => ['S' => $key]]]);
// Act.
$this->storeKeyClient->delete($key);
// Assert in arrange.
}
示例5: factory
/**
* Factory method to create a new Amazon DynamoDB Streams client using an array of configuration options.
*
* See http://docs.aws.amazon.com/aws-sdk-php/v2/guide/configuration.html#client-configuration-options
*
* @param array|Collection $config Client configuration data
*
* @return self
* @link http://docs.aws.amazon.com/aws-sdk-php/v2/guide/configuration.html#client-configuration-options
*/
public static function factory($config = array())
{
// Configure the custom exponential backoff plugin for DynamoDB throttling
$exceptionParser = new JsonQueryExceptionParser();
if (!isset($config[Options::BACKOFF])) {
$config[Options::BACKOFF] = new BackoffPlugin(DynamoDbClient::createDynamoDbBackoffStrategy($exceptionParser));
}
return ClientBuilder::factory(__NAMESPACE__)->setConfig($config)->setConfigDefaults(array(Options::VERSION => self::LATEST_API_VERSION, Options::SERVICE_DESCRIPTION => __DIR__ . '/Resources/dynamodbstreams-%s.php'))->setExceptionParser($exceptionParser)->build();
}
示例6: processMessage
/**
* Processes message from SQS Queue
* @param QueueMessage $message
*/
private function processMessage(QueueMessage $message)
{
$body = \Keboola\Utils\objectToArray($message->getBody());
if (isset($body['container_id'], $body['container_name'], $body['container_stats'])) {
$containerName = $body['container_name'];
$jobIdAndRunId = $this->getJobIdAndRunIdFromContainerName($containerName);
if (!empty($jobIdAndRunId)) {
$containerStats = $body['container_stats'];
$networkRxBytes = strval(isset($containerStats['network']['rx_bytes']) ? $containerStats['network']['rx_bytes'] : 0);
$networkTxBytes = strval(isset($containerStats['network']['tx_bytes']) ? $containerStats['network']['tx_bytes'] : 0);
$updateExpression = 'SET dockerNetwork = :dockerNetwork';
$expressionAttributeValues = [':dockerNetwork' => ['M' => ['rxBytes' => ['N' => $networkRxBytes], 'txBytes' => ['N' => $networkTxBytes]]], ':newRxBytes' => ['N' => $networkRxBytes], ':newTxBytes' => ['N' => $networkTxBytes]];
$updateExpression .= ', syrupJobId = if_not_exists(syrupJobId, :syrupJobId)';
$expressionAttributeValues[':syrupJobId'] = ['S' => $jobIdAndRunId['jobId']];
$params = ['TableName' => $this->tableName, 'Key' => ['runId' => ['S' => $jobIdAndRunId['runId']]], 'UpdateExpression' => $updateExpression, 'ConditionExpression' => <<<EXPR
attribute_not_exists(dockerNetwork)
or (dockerNetwork.rxBytes < :newRxBytes or dockerNetwork.txBytes < :newTxBytes)
EXPR
, 'ExpressionAttributeValues' => $expressionAttributeValues, 'ReturnValues' => 'UPDATED_NEW'];
try {
$this->dynamoDbClient->updateItem($params);
} catch (DynamoDbException $e) {
if (strpos($e->getMessage(), 'ConditionalCheckFailedException') === false) {
throw $e;
}
}
}
}
}
示例7: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->dynamoDbClient = $this->getContainer()->get('queue.dynamodb_client');
$this->tableName = $this->getContainer()->getParameter('container_stats_dynamodb.table_name');
$tableName = $this->tableName;
$updateTableJson = <<<JSON
{
"TableName": "{$tableName}",
"GlobalSecondaryIndexUpdates": [
{
"Create": {
"IndexName": "sapiProjectId-sapiCreatedTime-index",
"KeySchema": [
{
"AttributeName": "sapiProjectId",
"KeyType": "HASH"
},
{
"AttributeName": "sapiCreatedTime",
"KeyType": "RANGE"
}
],
"Projection": {
"ProjectionType": "ALL"
},
"ProvisionedThroughput": {
"ReadCapacityUnits": 3,
"WriteCapacityUnits": 7
}
}
}
],
"AttributeDefinitions": [
{
"AttributeName": "sapiCreatedTime",
"AttributeType": "S"
},
{
"AttributeName": "sapiProjectId",
"AttributeType": "S"
}
]
}
JSON;
$updateTableArgs = \json_decode($updateTableJson, true);
try {
$this->dynamoDbClient->updateTable($updateTableArgs);
echo 'Index has been created' . "\n";
} catch (DynamoDbException $e) {
if (strpos($e->getMessage(), 'Attempting to create an index which already exists') !== false) {
echo 'Index already exists' . "\n";
} else {
throw $e;
}
}
}
示例8: saveData
/**
* Save marshaled data
*
* @param $id
* @param $data
* @return bool|\Guzzle\Service\Resource\Model
*/
public function saveData($id, $data)
{
if (empty($this->table)) {
return false;
}
$client_data = ['TableName' => $this->table, 'Item' => ['id' => ['S' => $id], 'item_status' => ['S' => 'entered'], 'payload' => ['M' => $this->marshallData($data)], 'date' => ['S' => utf8_encode((string) date('Y-m-d H:i:s'))]]];
$result = $this->client->putItem($client_data);
return $result;
}
示例9: saved
public function saved($model)
{
$attrs = $model->attributesToArray();
// $this->attributeFilter->filter($attrs);
try {
$this->dynamoDbClient->putItem(['TableName' => $model->getDynamoDbTableName(), 'Item' => $this->marshaler->marshalItem($attrs)]);
} catch (Exception $e) {
Log::info($e);
}
}
示例10: storeReferralCode
public function storeReferralCode($code, $user_id, $timestamp)
{
$data = ['code' => $code, 'user_id' => $user_id, 'timestamp' => $timestamp];
// TODO error handling
$response = $this->client->GetItem(['TableName' => 'tr_referralcodes', 'Key' => ['code' => ['S' => $code]]]);
if (!empty($response['Item'])) {
throw new \Exception('Code already exists');
}
$this->client->PutItem(['TableName' => 'tr_referralcodes', 'Item' => $this->marshaler->marshalItem($data)]);
}
示例11: write
/**
* {@inheritdoc}
*/
protected function write(array $record)
{
$filtered = $this->filterEmptyFields($record['formatted']);
if ($this->version === 3) {
$formatted = $this->marshaler->marshalItem($filtered);
} else {
$formatted = $this->client->formatAttributes($filtered);
}
$this->client->putItem(['TableName' => $this->table, 'Item' => $formatted]);
}
示例12: seed
protected function seed($attributes = [])
{
$item = ['id' => ['S' => str_random(36)], 'name' => ['S' => str_random(36)], 'description' => ['S' => str_random(256)], 'count' => ['N' => rand()]];
$item = array_merge($item, $attributes);
$this->dynamoDbClient->putItem(['TableName' => $this->testModel->getTable(), 'Item' => $item]);
return $item;
}
示例13: getJobsToFetchStatsFor
/**
* Scans table for specific items we want to update
* @return array
*/
private function getJobsToFetchStatsFor()
{
$params = ['TableName' => $this->tableName, 'FilterExpression' => <<<EXPR
attribute_exists(sapiProjectId)
and attribute_not_exists(componentName)
and not begins_with(runId, :notBeginsWith)
and (
attribute_not_exists(syrupJobId)
or
(attribute_exists(syrupJobId) and syrupJobId <> :syrupJobIdSyncAction)
)
and attribute_not_exists(hasSyrupJob)
EXPR
, 'Limit' => self::MAX_DOCUMENTS_TO_PROCESS, 'ExpressionAttributeValues' => [':notBeginsWith' => ['S' => 'p'], ':syrupJobIdSyncAction' => ['S' => '0']]];
$ids = [];
$marshaler = new Marshaler();
do {
if (isset($response) && isset($response['LastEvaluatedKey'])) {
$params['ExclusiveStartKey'] = $response['LastEvaluatedKey'];
}
$response = $this->dynamoDbClient->scan($params);
foreach ($response['Items'] as $item) {
$ids[] = $marshaler->unmarshalValue($item['runId']);
}
} while (isset($response['LastEvaluatedKey']) && count($ids) <= 5000);
return $ids;
}
示例14: getAll
protected function getAll($columns = [], $limit = -1)
{
$query = ['TableName' => $this->getTable()];
$op = 'Scan';
if ($limit > -1) {
$query['limit'] = $limit;
}
if (!empty($columns)) {
$query['AttributesToGet'] = $columns;
}
// If the $where is not empty, we run getIterator.
if (!empty($this->where)) {
// Primary key or index key condition exists, then use Query instead of Scan.
// However, Query only supports a few conditions.
if ($key = $this->conditionsContainIndexKey()) {
$condition = array_get($this->where, "{$key}.ComparisonOperator");
if (ComparisonOperator::isValidQueryDynamoDbOperator($condition)) {
$op = 'Query';
$query['IndexName'] = $this->dynamoDbIndexKeys[$key];
$query['KeyConditions'] = $this->where;
}
}
$query['ScanFilter'] = $this->where;
}
$iterator = $this->client->getIterator($op, $query);
$results = [];
foreach ($iterator as $item) {
$item = $this->unmarshalItem($item);
$model = new static($item, $this->dynamoDb);
$model->setUnfillableAttributes($item);
$results[] = $model;
}
return new Collection($results);
}
示例15: listTables
/**
* List tables via the list_tables call
* @param integer $limit
* @param string $exclusiveStartTableName
* @return Table\TableCollection
*/
public function listTables($limit = null, $exclusiveStartTableName = null)
{
if (null !== $this->logger) {
$this->log('List tables');
}
$parameters = array();
if (null !== $limit) {
$parameters['Limit'] = $limit;
}
if (null !== $exclusiveStartTableName) {
$parameters['ExclusiveStartTableName'] = $exclusiveStartTableName;
}
if (null !== $this->logger) {
$this->log('ListTable request paramaters : ' . print_r($parameters, true), Logger::DEBUG);
}
$response = $this->connector->listTables($parameters);
if (null !== $this->logger) {
$this->log('ListTable request response : ' . print_r($response, true), Logger::DEBUG);
}
$tables = new Table\TableCollection(isset($response['LastEvaluatedTableName']) ? $response['LastEvaluatedTableName'] : null);
if (!empty($response['TableNames'])) {
foreach ($response['TableNames'] as $table) {
$tables->add($table);
}
}
return $tables;
}