类java.lang.String不能在DynamoDB创建表时转换为Long类型


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

我想使用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上运行脚本出错

致命错误:Uncaught Aws'DynamoDb'Exception' dynamodbeexception: Aws错误码:SerializationException,状态码:400,AWS请求ID:AWS错误类型:客户端,AWS错误消息:类java.lang.String不能转换User-Agent: aws-sdk-php2/2.6.12 Guzzle/3.9.1 curl/7.36.0PHP/5.5.12抛出/var/app/current/aws/Aws/Common/Exception/NamespaceExceptionFactory.php第91行

我怀疑,因为错误是在谈论一个坏的字符串到长(数字)转换,你的DDB_READ_CAPACITY_UNITSDDB_WRITE_CAPACITY_UNITS值是作为$_SERVER字符串读取的问题。尝试将它们转换为整数。

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