1

I can't seem to find how to correctly call PutItem for a StringSet in DynamoDB through API Gateway. If I call it like I would for a List of Maps, then I get objects returned. Example data is below.

{
    "eventId": "Lorem",
    "eventName": "Lorem",
    "companies": [
        {
            "companyId": "Lorem",
            "companyName": "Lorem"
        }
    ],
    "eventTags": [
        "Lorem",
        "Lorem"
    ]
}

And my example template call for companies:

"companies" : {
     "L": [
          #foreach($elem in $inputRoot.companies) {
            "M": {
              "companyId": {
                "S": "$elem.companyId"
              },
              "companyName": {
                "S": "$elem.companyName"
              }
            }
        } #if($foreach.hasNext),#end
        #end
     ]
}

I've tried to call it with String Set listed, but it errors out still and tells me that "Start of structure or map found where not expected" or that serialization failed.

"eventTags" : {
      "SS": [
        #foreach($elem in $inputRoot.eventTags) {
           "S":"$elem"
        } #if($foreach.hasNext),#end
        #end
      ]
    }

What is the proper way to call PutItem for converting an array of strings to a String Set?

1 Answers1

1

If you are using JavaScript AWS SDK, you can use document client API (docClient.createSet) to store the SET data type.

docClient.createSet - converts the array into SET data type

var docClient = new AWS.DynamoDB.DocumentClient();   

     var params = {
    TableName:table,
    Item:{
        "yearkey": year,
        "title": title       
        "product" : docClient.createSet(['milk','veg'])        
    }
};
notionquest
  • 37,595
  • 6
  • 111
  • 105