updateItem

abstract suspend fun updateItem(input: UpdateItemRequest): UpdateItemResponse

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.

Samples

import aws.sdk.kotlin.services.dynamodb.model.AttributeValue
import aws.sdk.kotlin.services.dynamodb.model.ReturnValue
fun main() { 
   //sampleStart 
   // This example updates an item in the Music table. It adds a new attribute (Year) and modifies the
// AlbumTitle attribute. All of the attributes in the item, as they appear after the update, are returned in the
// response.
val resp = dynamoDbClient.updateItem {
    tableName = "Music"
    key = mapOf<String, AttributeValue>(
        "Artist" to AttributeValue.S("Acme Band"),
        "SongTitle" to AttributeValue.S("Happy Day")
    )
    updateExpression = "SET #Y = :y, #AT = :t"
    expressionAttributeNames = mapOf<String, String>(
        "#Y" to "Year",
        "#AT" to "AlbumTitle"
    )
    expressionAttributeValues = mapOf<String, AttributeValue>(
        ":y" to AttributeValue.N("2015"),
        ":t" to AttributeValue.S("Louder Than Ever")
    )
    returnValues = ReturnValue.fromValue("ALL_NEW")
} 
   //sampleEnd
}