We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon with DynamoDb

I am trying to connect to DynamoDB using AWS SDK Version 3. In my di.php file I have written code

$di->set( "dynamodb",

function () use ($config) {

    return new \Aws\DynamoDb\DynamoDbClient(array(
        'version' => '2012-08-10',
        'region' => $config->dynamodb->region,
        'credentials' => array(
            'key' => $config->dynamodb->key,
            'secret' => $config->dynamodb->secret,
        ),
    ));

} );

In my controller when i do this: $ds = $this->getDi()->get('dynamodb');

Its showing error: { "error": 0, "error_description": "The dynamodb service does not have version: 22." }

It would be very helpfull if someone please point out what is missing in my code.
Thanks

edited Jul '17

Can you connect directly with their client, w/o Phalcon? using only \Aws\DynamoDb\DynamoDbClient?

Also why don't you autoload that namespace via Phalcon Loader component?



5.8k

Without using Phalcon i can connect using Aws\Sdk . I can connect & create table.

If i use that namespace in phalcon then i am getting same error: The dynamodb service does not have version: latest

edited Jul '17

So this works for you:

$client = new \Aws\DynamoDb\DynamoDbClient(['yourArrayParams....']);

While Phalcon service definition does not?

If that error comes from that external lib you're using, as it looks that it does - try loading it via Phalcon Loader, it might be that not all dependencies of that lib are loaded or their paths are invalid in relation to runtime of your app.

Also, set your service definition as shared. And then call it with getShared("name");

Last but not least - provide full server environment - PHP version, Phalcon version, OS etc.



5.8k
Accepted
answer
edited Aug '17

I can connect using \Aws\Sdk. This is connection code in DI file.

$di->set(
    "dynamodb",
    function () use ($config) {
        return new \Aws\Sdk(array(
            'version' => $config->dynamodb->version,
            'region' => $config->dynamodb->region,
            'credentials' => array(
                'key' => $config->dynamodb->key,
                'secret' => $config->dynamodb->secret,
            ),
        'endpoint' => $config->dynamodb->endpoint,
        ));
    }
);

In controller I can get the dynamodb object as:

$db = $this->getDi()->get('dynamodb');
$dynamodb = $db->createDynamoDb();