A developer needs to rename the primary key value of an existing item in an Amazon DynamoDB table because the business identifier has changed. Which approach will accomplish this requirement while following DynamoDB best practices?
Use UpdateItem with an UpdateExpression to set the new value for the key attribute.
Delete the existing item and recreate it with a PutItem request that includes the new primary key value.
Create a global secondary index and update the key through the index, which automatically propagates the change to the base table.
Run an ALTER TABLE command in the AWS Management Console to rename the key.
DynamoDB does not permit changes to an item's primary key with UpdateItem or any other in-place operation. The correct way to 'rename' a key is to delete the original item (DeleteItem) and then recreate it (PutItem or BatchWriteItem) with the new key value. Primary key immutability applies regardless of whether the table uses a simple partition key or a composite partition-and-sort key. Local and global secondary indexes also cannot be used to alter the underlying key of an item; they merely provide additional query paths. SQL-style ALTER TABLE statements are not supported in DynamoDB.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
Why can't we change the primary key in DynamoDB?
Open an interactive chat with Bash
What are the types of primary keys in DynamoDB?
Open an interactive chat with Bash
What does flexible schema mean in DynamoDB if the primary key can't change?
Open an interactive chat with Bash
AWS Cloud Practitioner CLF-C02
Cloud Technology and Services
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access