当DynamoDB创建表时,类java.lang.String无法转换为Long

时间:2014-07-18 05:49:11

标签: php amazon-web-services amazon-s3 elastic-beanstalk

我想使用php-aws-sdk

创建dynamodb表
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;

它在本地计算机上成功运行,但是我在Elasticbeanstalk上运行脚本时出错了

  

致命错误:未捕获的Aws \ DynamoDb \ Exception \ DynamoDbException:AWS   错误代码:SerializationException,Status Code:400,AWS Request ID:   HTTCDOVSES4RU0V8IVIQFGREL7VV4KQNSO5AEMVJF66Q9ASUAAJG,AWS错误类型:   客户端,AWS错误消息:无法转换类java.lang.String   到一个很长的用户代理:aws-sdk-php2 / 2.6.12 Guzzle / 3.9.1 curl / 7.36.0   PHP / 5.5.12引入   /var/app/current/aws/Aws/Common/Exception/NamespaceExceptionFactory.php   在第91行

1 个答案:

答案 0 :(得分:2)

我怀疑,因为错误是关于长(数字)转换的错误字符串,所以DDB_READ_CAPACITY_UNITSDDB_WRITE_CAPACITY_UNITS值是$_SERVER的字符串读取问题。尝试将它们转换/转换为整数。

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