[AWS] [DynamoDB]通过PhP SDK连接到数据库

I am new to AWS. I have installed an EC2 server which processes PhP code. I am able to administrate the DB through the Amazon website. I'm trying to access my DynamoDB table with the following code:

use Aws\DynamoDb\DynamoDbClient;      
    try {             
        $client = DynamoDbClient::factory(array(
            'profile' => 'default', // access ID + secret are in the .aws/credentials file
            'region' => Region::EU_WEST_1 // also tried with "eu-west-1"
        ));              
        echo "after client instanciation"; // this is not displayed

        $response = $client->getItem([
            'TableName' => 'Child',
            'Key' => [
                'ChildID' => 'Nicolas'
                ]
        ]);
        print_r ($response['Item']);
    } catch (Exception $e) {
        echo '<p>Exception received : ',  $e->getMessage(), "
</p>";
    }

I'm not getting any exception. The child I'm trying to get isn't displayed (I did create it). Also tried with the putItem method but it didn't add anything to the DB.

I think you are missing the data type in the key:

$response = $dynamodb->getItem([
'TableName' => 'Child',
'Key' => [
    'ChildID' => [ 'S' => 'Nicolas' ]
]

]);

Now you should get the output, you can refer this Link.

Try using the following code, it allows you to pass public and secret keys through parameters.

$client = new DynamoDbClient([
'version' => 'latest',
'region' => 'ap-northeast-1',
'credentials' => [
'key' => 'A5ITUTLAK7W47NNNNQ',
'secret' => 'DrsEjmEMs4PUPIY5/12a/cpUB7JVVcKLahFz826p'
]
]);

try {   
$result = $client->getItem(array(
'ConsistentRead' => true,
'TableName' => 'fruits',
'Key' => array(
'id' => array('S' => '1')
)
));

Replace the keys with yours.

Reference: https://solutionarchitects.guru/viewtopic.php?f=30&t=27