AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.
Container for the parameters to the UpdateItem operation. Edits an existing item's attributes, or adds a new item to the table if it does not already exist. You can put, delete, or add attribute values. You can also perform a conditional update on an existing item (insert a new attribute name-value pair if it doesn't exist, or replace an existing name-value pair if it has certain expected attribute values).
You can also return the item's attribute values in the same UpdateItem
operation
using the ReturnValues
parameter.
Namespace: Amazon.DynamoDBv2.Model
Assembly: AWSSDK.DynamoDBv2.dll
Version: 3.x.y.z
public class UpdateItemRequest : AmazonDynamoDBRequest IAmazonWebServiceRequest
The UpdateItemRequest type exposes the following members
Name | Description | |
---|---|---|
UpdateItemRequest() |
Empty constructor used to set properties independently even when a simple constructor is available |
|
UpdateItemRequest(string, Dictionary<String, AttributeValue>, Dictionary<String, AttributeValueUpdate>) |
Instantiates UpdateItemRequest with the parameterized properties |
|
UpdateItemRequest(string, Dictionary<String, AttributeValue>, Dictionary<String, AttributeValueUpdate>, ReturnValue) |
Instantiates UpdateItemRequest with the parameterized properties |
Name | Type | Description | |
---|---|---|---|
AttributeUpdates | System.Collections.Generic.Dictionary<System.String, Amazon.DynamoDBv2.Model.AttributeValueUpdate> |
Gets and sets the property AttributeUpdates.
This is a legacy parameter. Use |
|
ConditionalOperator | Amazon.DynamoDBv2.ConditionalOperator |
Gets and sets the property ConditionalOperator.
This is a legacy parameter. Use |
|
ConditionExpression | System.String |
Gets and sets the property ConditionExpression. A condition that must be satisfied in order for a conditional update to succeed. An expression can contain any of the following:
For more information about condition expressions, see Specifying Conditions in the Amazon DynamoDB Developer Guide. |
|
Expected | System.Collections.Generic.Dictionary<System.String, Amazon.DynamoDBv2.Model.ExpectedAttributeValue> |
Gets and sets the property Expected.
This is a legacy parameter. Use |
|
ExpressionAttributeNames | System.Collections.Generic.Dictionary<System.String, System.String> |
Gets and sets the property ExpressionAttributeNames.
One or more substitution tokens for attribute names in an expression. The following
are some use cases for using
Use the # character in an expression to dereference an attribute name. For example, consider the following attribute name:
The name of this attribute conflicts with a reserved word, so it cannot be used directly
in an expression. (For the complete list of reserved words, see Reserved
Words in the Amazon DynamoDB Developer Guide.) To work around this, you
could specify the following for
You could then use this substitution in an expression, as in this example:
Tokens that begin with the : character are expression attribute values, which are placeholders for the actual value at runtime. For more information about expression attribute names, see Specifying Item Attributes in the Amazon DynamoDB Developer Guide. |
|
ExpressionAttributeValues | System.Collections.Generic.Dictionary<System.String, Amazon.DynamoDBv2.Model.AttributeValue> |
Gets and sets the property ExpressionAttributeValues. One or more values that can be substituted in an expression.
Use the : (colon) character in an expression to dereference an attribute value.
For example, suppose that you wanted to check whether the value of the
You would first need to specify
You could then use these values in an expression, such as this:
For more information on expression attribute values, see Condition Expressions in the Amazon DynamoDB Developer Guide. |
|
Key | System.Collections.Generic.Dictionary<System.String, Amazon.DynamoDBv2.Model.AttributeValue> |
Gets and sets the property Key. The primary key of the item to be updated. Each element consists of an attribute name and a value for that attribute. For the primary key, you must provide all of the attributes. For example, with a simple primary key, you only need to provide a value for the partition key. For a composite primary key, you must provide values for both the partition key and the sort key. |
|
ReturnConsumedCapacity | Amazon.DynamoDBv2.ReturnConsumedCapacity |
Gets and sets the property ReturnConsumedCapacity. |
|
ReturnItemCollectionMetrics | Amazon.DynamoDBv2.ReturnItemCollectionMetrics |
Gets and sets the property ReturnItemCollectionMetrics.
Determines whether item collection metrics are returned. If set to |
|
ReturnValues | Amazon.DynamoDBv2.ReturnValue |
Gets and sets the property ReturnValues.
Use
There is no additional cost associated with requesting a return value aside from the small network and processing overhead of receiving a larger response. No read capacity units are consumed. The values returned are strongly consistent. |
|
ReturnValuesOnConditionCheckFailure | Amazon.DynamoDBv2.ReturnValuesOnConditionCheckFailure |
Gets and sets the property ReturnValuesOnConditionCheckFailure.
An optional parameter that returns the item attributes for an There is no additional cost associated with requesting a return value aside from the small network and processing overhead of receiving a larger response. No read capacity units are consumed. |
|
TableName | System.String |
Gets and sets the property TableName. The name of the table containing the item to update. You can also provide the Amazon Resource Name (ARN) of the table in this parameter. |
|
UpdateExpression | System.String |
Gets and sets the property UpdateExpression. An expression that defines one or more attributes to be updated, the action to be performed on them, and new values for them.
The following action values are available for
You can have many actions in a single expression, such as the following: For more information on update expressions, see Modifying Items and Attributes in the Amazon DynamoDB Developer Guide. |
This example shows how to update an item in a table.
// Create a client AmazonDynamoDBClient client = new AmazonDynamoDBClient(); // Define item key // Hash-key of the target item is string value "Mark Twain" // Range-key of the target item is string value "The Adventures of Tom Sawyer" Dictionary<string, AttributeValue> key = new Dictionary<string, AttributeValue> { { "Author", new AttributeValue { S = "Mark Twain" } }, { "Title", new AttributeValue { S = "The Adventures of Tom Sawyer" } } }; // Define attribute updates Dictionary<string, AttributeValueUpdate> updates = new Dictionary<string, AttributeValueUpdate>(); // Update item's Setting attribute updates["Setting"] = new AttributeValueUpdate() { Action = AttributeAction.PUT, Value = new AttributeValue { S = "St. Petersburg, Missouri" } }; // Remove item's Bibliography attribute updates["Bibliography"] = new AttributeValueUpdate() { Action = AttributeAction.DELETE }; // Add a new string to the item's Genres SS attribute updates["Genres"] = new AttributeValueUpdate() { Action = AttributeAction.ADD, Value = new AttributeValue { SS = new List<string> { "Bildungsroman" } } }; // Create UpdateItem request UpdateItemRequest request = new UpdateItemRequest { TableName = "SampleTable", Key = key, AttributeUpdates = updates }; // Issue request client.UpdateItem(request);
.NET Core App:
Supported in: 3.1
.NET Standard:
Supported in: 2.0
.NET Framework:
Supported in: 4.5, 4.0, 3.5