Whatever message this page gives is out now! Go check it out!

UpdateItem

Last update:
May 18, 2026

Description

This function makes changes to an existing item's attributes, or adds a new item to the table, if the item does not exist. Using this function, you can also perform a conditional update on an existing item.
For more information, see UpdateItem.

Category

History

ColdFusion (2021 release): Added this function.

Syntax

serviceHandle.updateItem(requestParameters)

Parameters

See request parameters of UpdateItem.

Example

<cfscript> 
    cred = { 
        "credentialAlias" : "myalias", 
        "vendorName" : "AWS", 
        "region" : "us-east-2", 
        "secretAccessKey" : "xxxxx", 
        "accessKeyId" : "xxxx" 
  } 
     
    conf={ 
        "serviceName"="DYNAMODB" 
    } 
     
    dynamo=getCloudService(cred, conf) 
    tableName="NewProductCatalog" 
 
    Stage 1: Create a table 
    createTableStruct={ 
        "TableName": "#tableName#", 
        "KeySchema": [ 
            { 
                "AttributeName": "id", 
                "KeyType": "HASH" 
            } 
        ], 
        "AttributeDefinitions": [ 
            { 
                "AttributeName": "id", 
                "AttributeType": "N" 
            } 
        ], 
        "ProvisionedThroughput": { 
            "ReadCapacityUnits": 10, 
            "WriteCapacityUnits": 10 
        } 
    } 
 
    dynamo.createTable(createTableStruct) 
    sleep(20000) 
 
    // Stage 2: Insert an item 
    putItemStruct = { 
        "TableName": "#tableName#", 
        "Item":{ 
            "id": { 
                "N": 550 
            }, 
            "Title": { 
                "S": "Macbeth" 
            }, 
            "Price": { 
                "N": "2" 
            } 
        }, 
        "ReturnValues": "ALL_OLD" 
    } 
    dynamo.putItem(putItemStruct,{"hasType": true}) 
    sleep(20000) 
    //abort; 
 
    // Stage 3: Update the item that was inserted 
    updateItemStruct={ 
        "TableName": "#tableName#", 
        "Key": { 
            "id": { 
                "N": 550 
            } 
        }, 
        "UpdateExpression": "set Title = :val1", 
        "ConditionExpression": "Price = :val2", 
        "ExpressionAttributeValues": { 
            ":val1": {"S": "Hamlet"}, 
            ":val2": {"N": "2"} 
        }, 
        "ReturnValues": "ALL_NEW" 
    } 
    try{ 
        result = dynamo.updateItem(updateItemStruct, {"hasType": true}) 
        if(result.Attributes.Title.S == "Hamlet") { 
            writeOutput("Title changed successfully<br/>") 
        } else { 
            writeOutput("Failed to change the title<br/>") 
        } 
    } 
    catch (any e){ 
        writeDump(e) 
    } 
         
</cfscript>

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page