1
votes
require "config.php";
require __DIR__ . '/vendor/autoload.php';
$sdk = new Aws\Sdk([
    'region'   => 'us-east-1',
    'version'  => 'latest',
    'credentials' => array(
        'key' => $global_access_key,
        'secret'  => $global_secret_key,
      ),
]);

$dynamodb = $sdk->createDynamoDb();

$response = $dynamodb->getItem([
    'TableName' => $global_table_name,
'Key' => [
    'userid' => [ 'N' => '1' ]
    ]
]);

var_dump($response);
die;

when i try to run this code it gives the error which is defined as :

Fatal error: Uncaught exception 'Aws\DynamoDb\Exception\DynamoDbException' with message 'Error executing "GetItem" on "https://dynamodb.us-east-1.amazonaws.com"; AWS HTTP error: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)' in C:\wamp\www\practice\vendor\aws\aws-sdk-php\src\WrappedHttpHandler.php on line 159

2

2 Answers

1
votes
$sdk = new Aws\Sdk([
'region'   => 'us-east-1',
'version'  => 'latest',
'credentials' => array(
    'key' => $global_access_key,
    'secret'  => $global_secret_key,
  ),
'signature_version' => 'v4',
'http'    => [
    'verify' => false
]
]);

got an answer from reading the documentation

1
votes

Rather than disabling the SSL verification, which might leads to a man in the middle attack. below solution would be more secure and appropriate.

  1. download the latest certificate file from http://curl.haxx.se/ca/cacert.pem
  2. save it in a path accessible by your code. (eg:- C:\nginx\cert\cacert.pem)
  3. depending on the version of the aws-sdk-php that you are using modify your code as below.

version 2.X:-

$aws = Aws\Common\Aws::factory(array(
 'region' => 'us-west-2',
 'key' => '****',
 'secret' => '****',
 'ssl.certificate_authority' => 'C:\nginx\cert\cert.pem'
));

version 3.X :-

$client = new DynamoDbClient([
    'region'  => 'us-west-2',
    'version' => 'latest',
    'http'    => [
        'verify' => 'C:\nginx\cert\cert.pem'
    ]
]);

refference :-

https://s3.cn-north-1.amazonaws.com.cn/aws-dam-prod/china/pdf/aws-sdk-php-guide.pdf

http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/configuration.html#verify