needing to make an api on my EC2 instance of AWS to interact with dynamoDB. GET, POST, PUT, DELETE all are required.
Things that are working:
- I have other php working on the same EC2 instance, so that seems ok
- I got composer.phar installed on the instance through my mac's terminal.
- I have some echo's from the php code working, so I know some of the requires and uses are ok
first bit of code in my php file:
<?php ...
...
$tableName = 'lab_instruments';
echo "past table name \n";
$assetNumber = 'OS014005';
$name = 'Billy';
$make = 'Hamilton';
$model = 'STARlet';
echo "past model \n";
$newItem = '
{
"assetNumber": "' . $assetNumber . '",
"name": "' . $name . '",
"make": "' . $make . '",
"model": "' . $model . '"
}
';
echo "newItem: " . $newItem . "\n";
$item = $marshaler->marshalJson($newItem);
$params = [
'TableName' => 'lab_instruments',
'Item' => [
"assetNumber" => array('S' => $assetNumber),
"name"=> array('S' => $name),
"make" => array('S' => $make),
"model" => array('S' => $model)
] //$item
];
try {
echo "in try \n";
$result = $dynamodb->putItem($params);
echo "Added item: $assetNumber - $name\n";
} catch (DynamoDbException $e) {
echo "Unable to add item:\n";
echo $e->getMessage() . "\n";
}
?>
with @BradKent's help, I've got a bit further, and my newest echo to the browser is here:
past table name past model newItem: { "assetNumber": "OS014005", "name": "Billy", "make": "Hamilton", "model": "STARlet" } in try Fatal error: Uncaught exception 'Aws\Exception\CredentialsException' with message 'Error retrieving credentials from the instance profile metadata server. (Client error:
GET http://169.254.169.254/latest/meta-data/iam/security-credentials/
resulted in a404 Not Found
response: Aws\Credentials{closure}(Array)1 /var/www/html/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(2, Array, Array) #2
/var/www/html/vendor/guzzlehttp/promises/src/TaskQueue.php(61): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise{closure}() #3 /var/www/html/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(96): GuzzleHttp\Promise\TaskQueue->run() #4 /var/www in /var/www/html/vendor/aws/aws-sdk-php/src/Credentials/InstanceProfileProvider.php on line 79
I'm very grateful to have gotten further, but not sure how to address this issue adding the new item