Linked Questions

Popular Questions

update(add) dynamodb with lambda function

Asked by At

I have done a lot of research and the topic does not have enough source for juniors like me. Everything I could find was case specific that was making it impossible to understand. Therefore for myself and for the people who will read this in the future I will not make my question too case specific.

I have created a table record on DynamoDB with the following lambda function:

const AWS = require('aws-sdk');
const dynamodb = new AWS.DynamoDB({region: 'us-east-2', apiVersion: '2012-08-10'})

exports.handler = (event, context, callback) => {
    console.log(event)

    const params = {
        Item: {
            "UserId": {
                S: "global" 
            },
            "search": {
                        SS: [
                             "" + event.hashtag
                            ]
            }
        },
        TableName: "crypto-app"
    };
    dynamodb.putItem(params, function(err, data) {
        if (err) {
            callback(err)
        } else {
            callback(null, data)
        }
    });
};

this is creating a simple string set

 {
  "search": {
    "SS": [
      "london"
    ]
  },
  "UserId": {
    "S": "global"
  }
}

how can I add more strings to my string set with a lambda function to make it like this?

{
  "search": {
    "SS": [
      "london", "tokyo", "moskow" 
    ]
  },
  "UserId": {
    "S": "global"
  }
}

Related Questions