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?

2
  • Are you using javascript? Commented Jun 12, 2017 at 18:27
  • I'm doing this directly through the body template in API gateway. I'm just specifying a format of application/json. Commented Jun 12, 2017 at 22:09

1 Answer 1

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'])        
    }
};
Sign up to request clarification or add additional context in comments.

1 Comment

I ended up going this route and using the JavaScript SDK in Lambda instead. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.