Reputation: 3917
I am having some trouble connecting to my local instance of DynamoDB. I am launching the server by running the following at the command prompt:
C:\Program Files\Java\jre8\bin>java -Djava.library.path=D:\DynamoDB\DynamoDBLoca
l_lib -jar D:\DynamoDB\DynamoDBLocal.jar
My PHP code looks like this:
<?
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
)
));
When I execute the createTable() command, I don't see any activity in my command prompt window where the server is running and I get the following error:
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
I am a little confused because it seems like the code isn't hitting the local server what-so-ever which would obviously prevent anything else from working. Any input/thoughts would be much appreciated.
Upvotes: 4
Views: 3275
Reputation: 3917
I hate to answer this so quickly but it turned out that the key/secret are required even for local DynamoDB usage. It's odd this isn't mentioned on the AWS site but here is the working code for connecting, after that all other examples have worked:
$client = \Aws\DynamoDb\DynamoDbClient::factory(array(
'credentials' => [
'key' => 'YOUR_KEY',
'secret' => 'YOUR_SECRET',
],
'region' => 'us-west-2',
'endpoint' => 'http://localhost:8000'
));
Upvotes: 5