GetItem

Description

The GetItem function retrieves a set of attributes for an already inserted item with the specified primary key.

For more information, see GetItem.

Category

History

Adobe ColdFusion (2021 release): Added this function.

Syntax

serviceHandle.getItem(requestParameters)

Parameters

See request parameters for GetItem.

Example

<cfscript>
  cred = {
    "credentialAlias" : "myalias",
    "vendorName" : "AWS",
    "region" : "us-east-2",
    "secretAccessKey" : "xxxxx",
    "accessKeyId" : "xxxx"
  }
  config = {
    "serviceName" = "DYNAMODB"
  }
  dynamo = getCloudService(cred, config)
  movieName="Movies009"
  // Stage 1: create a table
  tableStruct={
    TableName : "#movieName#",
    KeySchema:[
        { AttributeName: "year", KeyType: "HASH"},  //Partition key
        { AttributeName: "title", KeyType: "RANGE"}  //Sort key
    ],
    AttributeDefinitions:[
        { AttributeName: "year", AttributeType: "N" },
        { AttributeName: "title", AttributeType: "S" }
    ],
    ProvisionedThroughput:{
        ReadCapacityUnits: 10,
        WriteCapacityUnits: 10
    }
 }
 dynamo.createTable(tableStruct)
 sleep(3000)

 // Stage 2: insert an item into the table

 putItemStruct={
    "TableName":"#movieName#",
    "Item":{
      "year": {"N": 2019},
      "title": {"S": "Golden"}
    },
    "ReturnValues": "NONE"
 }

 try{
    putItemResponse=dynamo.putItem(putItemStruct,{"hasType": true})
    writeOutput("Item inserted successfully in the table.")
    writeDump(putItemResponse)
 }
 catch (any e){
    writeDump(e)
 }

 // Stage 3: get the inserted item
 getItemStruct={
    "TableName":"#movieName#",
    "Key":{
        "year":2019,
        "title":"Golden"
    },
    "ConsistentRead": true
 }
 try{
  getItemResponse=dynamo.getItem(getItemStruct,{
            "customResponse": true
        })
  writeOutput("Item successfully retrieved")
  writeDump(getItemResponse)
  }
 catch(any e){
    writeDump(e);
  }
</cfscript>

Output

GetItem output
GetItem output