1

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 a 404 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

Keith
  • 777
  • 8
  • 27
  • have you looked in the error logs? Add this to your script to output errors directly: `ini_set('display_errors', 1); error_reporting(E_ALL);` – Brad Kent Jul 14 '16 at 03:40
  • @BradKent, I'm new enough that it hadn't occurred to me, so I looked, repeating failure is: _PHP Fatal error: Class 'Aws\\Sdk' not found in /var/www/html/Asmt3/addInstr.php on line 22_ – Keith Jul 14 '16 at 03:44
  • for the reference of future browsers, I found the log via this command in the terninal: `sudo tail /var/log/httpd/error_log` – Keith Jul 14 '16 at 03:47
  • can you confirm that the AWS sdk is in the vendor directory? and that you've installed v3 of the the SDK? You [installed via composer](http://docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/installation.html)? – Brad Kent Jul 14 '16 at 04:04
  • `[...html]$ ls vendor/aws/aws-sdk-php ==> composer.json LICENSE.md NOTICE.md src` and I followed the instructions at _http://docs.aws.amazon.com/aws-sdk-php/v2/guide/installation.html_ which call for version 2.x – Keith Jul 14 '16 at 04:09
  • unless I'm mistaken, `$sdk = new Aws\Sdk($sharedConfig);` is v3 (use v3 unless you have a reason to be using v2) http://docs.aws.amazon.com/aws-sdk-php/v3/guide/ – Brad Kent Jul 14 '16 at 04:17
  • Have you seen here: http://stackoverflow.com/questions/27400563/aws-sdk-for-php-error-retrieving-credentials-from-the-instance-profile-metadata – Gaurav Dave Jul 14 '16 at 05:41

0 Answers0