php - SDK Error while trying to add caching to KMS -
i getting following error
fatal error: uncaught exception 'aws\common\exception\invalidargumentexception' message 'unable utilize caching specified options' in vendor/aws/aws-sdk-php/src/aws/common/credentials/credentials.php:305 stack trace: #0 vendor/aws/aws-sdk-php/src/aws/common/credentials/credentials.php(113): aws\common\credentials\credentials::createcache(object(aws\common\credentials\refreshableinstanceprofilecredentials), object(illuminate\cache\apcstore), 'credentials_214...') #1 vendor/aws/aws-sdk-php/src/aws/common/client/clientbuilder.php(431): aws\common\credentials\credentials::factory(object(guzzle\common\collection)) #2 vendor/aws/aws-sdk-php/src/aws/common/client/clientbuilder.php(227): aws\common\client\clientbuilder->getcredent in vendor/aws/aws-sdk-php/src/aws/common/credentials/credentials.php on line 305 with following code
use aws\kms\exception\kmsexception, aws\kms\kmsclient; .... public function __construct($region = 'us-east-1') { $this->cacheadapter = new illuminate\cache\apcstore(new illuminate\cache\apcwrapper()); $this->region = $region; $this->kms = kmsclient::factory([ 'credentials.cache' => $this->cacheadapter, 'region' => $this->region, ]); } i believe needs implement guzzle cacheadaperinterface not how go it?
i use caching service in front of sdk fixed problem.
<?php namespace library\cache\aws { use guzzle\cache\cacheadapterinterface cacheinterface; class apcadapter implements cacheinterface { /** * test if entry exists in cache. * * @param string $id cache id cache id of entry check for. * @param array $options array of cache adapter options * @return bool returns true if cache entry exists given cache id, false otherwise. */ public function contains($id, array $options = null) { return apc_exists($id); } /** * deletes cache entry. * * @param string $id cache id * @param array $options array of cache adapter options * @return bool true on success, false on failure */ public function delete($id, array $options = null) { return apc_delete($id); } /** * fetches entry cache. * * @param string $id cache id id of cache entry fetch. * @param array $options array of cache adapter options * @return string cached data or false, if no cache entry exists given id. */ public function fetch($id, array $options = null) { return apc_fetch($id); } /** * puts data cache. * * @param string $id cache id * @param string $data cache entry/data * @param int|bool $lifetime lifetime. if != false, sets specific lifetime cache entry * @param array $options array of cache adapter options * @return bool true if entry stored in cache, false otherwise. */ public function save($id, $data, $lifetime = false, array $options = null) { return apc_add($id, $data, intval($lifetime)); } } } namespace library\servicebuilder { use aws\common\aws servicebuilder, aws\dynamodb\dynamodbclient dynamodbclient, aws\kms\kmsclient kmsclient, library\cache\aws\apcadapter apcadapter; class aws { protected static $_instance = []; protected $_awsinstance; protected $_region; protected function __construct($region) { $cacheadapter = new apcadapter(); $this->_region = $region; $this->_awsinstance = servicebuilder::factory(null, [ 'credentials.cache' => $cacheadapter, 'region' => $region, ] ); } /** * @param string $region [opt, default=us-east-1] * @static * @return \engrade\servicebuilder\aws */ public static function getinstance($region = 'us-east-1') { if (! array_key_exists($region, self::$_instance)) { self::$_instance[$region] = new self($region); } return self::$_instance[$region]; } /** * @return kmsclient */ public function getkmsclient() { return $this->_awsinstance->get('kms'); } /** * @return dynamodbclient */ public function getdynamodbclient() { return $this->_awsinstance->get('dynamodb'); } } } namespace { use library\servicebuilder servicebuilder aws\kms\exception\kmsexception, aws\kms\kmsclient; .... public function __construct($region = 'us-east-1') { $this->region = $region; $aws = servicebuilder\aws::getinstance(); $kms = $aws->getkmsclient(); $this->kms = $kms::factory([ 'region' => $this->region, ]); } }
Comments
Post a Comment