DynamoDB Local Basic PHP安装程序

时间:2014-09-24 16:51:25

标签: php windows amazon-dynamodb

我在连接到我的本地DynamoDB实例时遇到了一些麻烦。我通过在命令提示符下运行以下命令来启动服务器:

C:\Program Files\Java\jre8\bin>java -Djava.library.path=D:\DynamoDB\DynamoDBLoca
l_lib -jar D:\DynamoDB\DynamoDBLocal.jar

我的PHP代码如下所示:

<?

require './aws-autoloader.php';
use \Aws\DynamoDb\DynamoDbClient;

$client = \Aws\DynamoDb\DynamoDbClient::factory(array(
    'profile' => 'default',
    'region' => 'us-east-1',
    'base_url' => 'http://localhost:8000'
));


// create test table    
$client->createTable(array(
    'TableName' => 'errors',
    'AttributeDefinitions' => array(
        array(
            'AttributeName' => 'id',
            'AttributeType' => 'N'
        ),
        array(
            'AttributeName' => 'time',
            'AttributeType' => 'N'
        )
    ),
    'KeySchema' => array(
        array(
            'AttributeName' => 'id',
            'KeyType'       => 'HASH'
        ),
        array(
            'AttributeName' => 'time',
            'KeyType'       => 'RANGE'
        )
    ),
    'ProvisionedThroughput' => array(
        'ReadCapacityUnits'  => 10,
        'WriteCapacityUnits' => 20
    )
));

当我执行createTable()命令时,我在服务器运行的命令提示符窗口中看不到任何活动,我收到以下错误:

Fatal error:  Uncaught exception 'Aws\Common\Exception\InstanceProfileCredentialsException' with message 'Error retrieving credentials from the instance profile metadata server. When you are not running inside of Amazon EC2, you must provide your AWS access key ID and secret access key in the "key" and "secret" options when creating a client or provide an instantiated Aws\Common\Credentials\CredentialsInterface object. ([curl] 28: Connection timed out after 5008 milliseconds [url] http://169.254.169.254/latest/meta-data/iam/security-credentials/)' in C:\xampp\htdocs\AWS\Aws\Common\InstanceMetadata\InstanceMetadataClient.php:85 Stack trace:
#0 C:\xampp\htdocs\AWS\Aws\Common\Credentials\RefreshableInstanceProfileCredentials.php(52): Aws\Common\InstanceMetadata\InstanceMetadataClient->getInstanceProfileCredentials()
#1 C:\xampp\htdocs\AWS\Aws\Common\Credentials\AbstractRefreshableCredentials.php(54): Aws\Common\Credentials\RefreshableInstanceProfileCredentials->refresh()
#2 C:\xampp\htdocs\AWS\Aws\Common\Signature\SignatureV4 in C:\xampp\htdocs\AWS\Aws\Common\InstanceMetadata\InstanceMetadataClient.php on line 85

我有点困惑,因为看起来代码并没有打到本地服务器,这显然会阻止其他任何工作。任何意见/想法都会非常感激。

1 个答案:

答案 0 :(得分:3)

我讨厌这么快回答这个问题但事实证明,即使对于本地DynamoDB的使用,也需要密钥/密钥。奇怪的是,在AWS网站上没有提到这一点,但这是连接的工作代码,之后所有其他示例都有效:

$client = \Aws\DynamoDb\DynamoDbClient::factory(array(
    'credentials' => [
        'key' => 'YOUR_KEY',
        'secret' => 'YOUR_SECRET',
    ],
    'region' => 'us-west-2',
    'endpoint' => 'http://localhost:8000'
));