2014-09-24 47 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