php使用DynamoDB,DynamoDB本地基本PHP设置

连接到本地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

我有些困惑,因为似乎代码至今未打中本地服务器,这显然会阻止其他任何事情.任何意见/想法将不胜感激.

解决方法:

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

$client = \Aws\DynamoDb\DynamoDbClient::factory(array(

'credentials' => [

'key' => 'YOUR_KEY',

'secret' => 'YOUR_SECRET',

],

'region' => 'us-west-2',

'endpoint' => 'http://localhost:8000'

));

标签:amazon-dynamodb,windows,php

来源: https://codeday.me/bug/20191121/2050183.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值