2014-09-24 55 views
1

我在连接到本地DynamoDB实例时遇到了一些问题。DynamoDB Local Basic PHP设置

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

我不愿意这么快回答,但事实证明,即使对于本地DynamoDB的使用,密钥/密钥也是必需的。很奇怪,这是不是对AWS网站提及,但这里是连接工作代码后,所有其他的例子已经工作:

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

DynamoDB地方确实需要的凭据,但他们不必是真实的: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Tools.DynamoDBLocal.html#Tools.DynamoDBLocal.UsageNotes – 2014-09-25 15:35:32

+1

但是,在这种情况下,错误来自SDK本身,因为SDK需要凭据来创建请求的签名。再次,他们不必是真正的凭据,因为您实际上没有使用AWS进行身份验证来访问DynamoDB Local。 – 2014-09-25 15:36:37

+0

谢谢@JeremyLindblom!现在事情确实非常顺利,我开始将5GB Mongo数据迁移到DynamoDB。再次感谢并保重! – 2014-09-25 15:59:40