Deleting Attribute in DynamoDB

dynamodb remove attribute from all items
dynamodb update multiple items
dynamodb update item java
dynamodb update all items
dynamodb update expression javascript
dynamodb remove item from list
dynamodb set
dynamodb delete all items nodejs

I'm trying to figure out the best way to delete an attribute from an item in Dynamo DB. Below is what I tried, but I get an exception saying that DELETE is not a supported for either type N or S.

Exception in thread "main" Status Code: 400, AWS Service: AmazonDynamoDB, AWS Request ID: 09MRO4PVTJ8IK6OHLKSM551REJVV4KQNSO5AEMVJF66Q9ASUAAJG, AWS Error Code: ValidationException, AWS Error Message: One or more parameter values were invalid: Action DELETE is not supported for the type N at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:544) at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:284) at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:169) at >com.amazonaws.services.dynamodb.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:675) at >com.amazonaws.services.dynamodb.AmazonDynamoDBClient.updateItem(AmazonDynamoDBClient.java:371)

Key pk = new Key(new AttributeValue().withN(Long.toString(123)));
AttributeValueUpdate avu = new AttributeValueUpdate(new AttributeValue().withN("555"), "DELETE");
Map<String, AttributeValueUpdate> m = new HashMap<String, AttributeValueUpdate>();
m.put(String.valueOf(555), avu);
UpdateItemRequest uir = new UpdateItemRequest("users", pk, m);
dynamoDB.updateItem(uir);

One point of confusion is why the attribute value matters for a deletion. I really want to delete an attribute name and any associated values, but couldn't find the appropriate way to do that in the SDK.

Help would be appreciated.

I could have sworn I already tried this but by replacing the AttributeValue with a null value it works:

Key pk = new Key(new AttributeValue().withN(Long.toString(123)));
AttributeValueUpdate avu = new AttributeValueUpdate(null, "DELETE");
Map<String, AttributeValueUpdate> m = new HashMap<String, AttributeValueUpdate>();
m.put(String.valueOf(555), avu);
UpdateItemRequest uir = new UpdateItemRequest("users", pk, m);
dynamoDB.updateItem(uir);

Deleting Attribute in DynamoDB, Learn how to update and delete Items with AWS DynamoDB. to an Item or modify an existing attribute;; REMOVE: Used to delete attributes from an Item. DELETE: Used to remove items from a Set. Let's check a few of these by example. Using the SET update clause. The most common update clause is "SET", which is used to add an attribute to an Item if the attribute does not exist or to overwrite the existing attribute value if it does exist.

This also works.

Table table = dynamoDB.getTable("users");
table.updateItem(new PrimaryKey("<MY HASH KEY NAME>", <MY HASH VALUE>), new AttributeUpdate("columnToRemove").delete());

or you can even use Expressions in an Item Update.

REMOVE - Removes one or more attributes from an item.

Updating & Deleting Items, If an item with the specified primary key is found in the table, the following values perform the following actions: PUT - Adds the specified attribute to the item. DELETE - Removes the attribute and its value, if no value is specified for DELETE . In step 3 of this tutorial, add, modify, and delete data in a DynamoDB table using the AWS SDK for JavaScript.

To delete an Attribute from Dynamo DB while Updating an item of the table

 UpdateItemRequest updateItemRequest =new UpdateItemRequest().withTableName(tableName).withKey(key);
 updateItemRequest.addAttributeUpdatesEntry("privileges",new AttributeValueUpdate()
          .withAction(AttributeAction.DELETE));

updateItemRequest.addAttributeUpdatesEntry("description", new AttributeValueUpdate()
          .withValue(new AttributeValue().withS("description")));

In above Example, First I removed privileges from Item and then updated description in Item.

AttributeUpdates, you choose depends primarily on the access patterns for your applications and the size of the data items. Maybe this is obvious for you, but here is an example of an issue I faced when I started designing application with DynamoDB: Every column you use in a query must be a partition key or an index. Indexes require additional read capacity units and write capacity units .

Deleting Data from a Table, Add, modify, and delete data in a DynamoDB table using the AWS SDK for Java. This code adds an item that has primary key ( year , title ) and info attributes. Deleting Data from a Table In SQL, the DELETE statement removes one or more rows from a table. Amazon DynamoDB uses the DeleteItem operation to delete one item at a time.

dynamodb, DynamoDB - Delete Items - Deleting an item in the DynamoDB only requires providing Map<String,Object> expressionAttributeValues = new HashMap<​String  When you delete a table, any indexes on that table are also deleted. If you have DynamoDB Streams enabled on the table, then the corresponding stream on that table goes into the DISABLED state, and the stream is automatically deleted after 24 hours. Use the DescribeTable action to check the status of the table.

Should Your DynamoDB Table Be Normalized or Denormalized , the DocumentClient has marshalled the JavaScript array as a DynamoDB List type. How would we remove the value “frylock” from the “friends” List attribute? Deletes a single item in a table by primary key. You can perform a conditional delete operation that deletes the item if it exists, or if it has an expected attribute value. In addition to deleting an item, you can also return the item's attribute values in the same operation, using the ReturnValues parameter.

Comments
  • Could you post the actual exception
  • @Layble: Glad you managed to resolve this yourself - could you please post your solution as an answer and accept it? Following up to your own question is perfectly reasonable and desired, as long as it has been a real open question in the first place. Thanks :)