php - class java.lang.String can not be converted to an Long while DynamoDB creating table

806

I want to create dynamodb table using php-aws-sdk

set_time_limit(0);
error_reporting(E_ALL);

require_once 'aws/aws-autoloader.php';

use Aws\DynamoDb\DynamoDbClient;

$ddb = DynamoDbClient::factory(array(
    'key'    => $_SERVER['AWS_KEY']),
    'secret' => $_SERVER['AWS_SECRET']),
    'region' => $_SERVER['AWS_REGION'])
));

$name = 'test';

$ddb->createTable(array(
    'TableName' => $name,
    'AttributeDefinitions' => array(
        array(
            'AttributeName' => 'Event ID',
            'AttributeType' => 'S'
        )
    ),
    'KeySchema' => array(
        array(
            'AttributeName' => 'Event ID',
            'KeyType' => 'HASH'
        )
    ),
    'ProvisionedThroughput' => array(
        'ReadCapacityUnits' => $_SERVER['DDB_READ_CAPACITY_UNITS']),
        'WriteCapacityUnits' => $_SERVER['DDB_WRITE_CAPACITY_UNITS']),
    )
));

echo $name;

It is working successfully on local machine, but I have error by running script on Elasticbeanstalk

Fatal error: Uncaught Aws\DynamoDb\Exception\DynamoDbException: AWS Error Code: SerializationException, Status Code: 400, AWS Request ID: HTTCDOVSES4RU0V8IVIQFGREL7VV4KQNSO5AEMVJF66Q9ASUAAJG, AWS Error Type: client, AWS Error Message: class java.lang.String can not be converted to an Long, User-Agent: aws-sdk-php2/2.6.12 Guzzle/3.9.1 curl/7.36.0 PHP/5.5.12 thrown in /var/app/current/aws/Aws/Common/Exception/NamespaceExceptionFactory.php on line 91

481

Answer

Solution:

I suspect, since the error is talking about a bad string to long (number) conversion, that yourDDB_READ_CAPACITY_UNITS andDDB_WRITE_CAPACITY_UNITS values are problem being read as strings from$_SERVER. Try casting/converting them to integers.

'ProvisionedThroughput' => array(
    'ReadCapacityUnits' => (int) $_SERVER['DDB_READ_CAPACITY_UNITS'],
    'WriteCapacityUnits' => (int) $_SERVER['DDB_WRITE_CAPACITY_UNITS'],
)

People are also looking for solutions to the problem: php - How to delete saved credit card numbers of completed orders from Magento?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.