Updating an item in the DynamoDB table using the AWS SDK for PHP
Let's understand how to update an item from the DynamoDB table using the AWS SDK for PHP.
Getting ready
To perform this operation, you can use the IDE of your choice.
How to do it…
Let's try to understand how to update a stored item in the DynamoDB table using PHP. The update request allows us to add a new attribute to the item, update the values of an attribute, or remove an attribute from the item:
Create an instance of the
DynamoDBClientand initialize it with the desired AWS region and credentials:$client = DynamoDbClient::factory(array( 'profile' => 'default', 'region' => 'us-east-1' ));Create the
Updateitem request and specify the details. Here, I want to add an attribute calledratingwith the value as5, update/reduce the value ofstockby2, and remove themnfrattribute from that item whoseprimarykeyidis10and the typephone:$response = $client->updateItem(array( 'TableName' => 'productTable...