0

I'm currently using dynamoose for managing records in dynamodb.

from my client I'm receiving a collection of insiders

insiders: [
  { uid: '123', name: 'Insider A' },
  { uid: '456', name: 'Insider B' },
  { uid: '789', name: 'Insider B' }
]

and my lambda function receives the collection thru insiders variable and I loop in each records. Inside loop I update the position of the records

module.exports.reorder = async (event) => {

  const klass = await getKlass.byEnv(process.env.STAGE, 'insider');
  const req = event.body
  var insiders = req.insiders;

  try {
    for (let [index, insider] of insiders.entries()) {
      console.log("Insider: ", insider);
      console.log("Index: ", index);
      await klass.update({ uid: insider.uid }, {
        $PUT: {
          position: index += 1
        }
      }, { condition: 'attribute_exists(uid)' })
    }
    return successResponse.message();
  } catch (err) {
    console.log("===============");
    console.error(err);
    console.log("===============");
    if (err && err.code == 'ConditionalCheckFailedException') {
      return noRecord404.notFound();
    }
  }
}

this is working fine when I'm testing it in my local but when I deploy it to AWS Lambda It's not being updated. I also put console.log inside loop and I'm getting the printed log.

AllenC
  • 2,754
  • 1
  • 41
  • 74

0 Answers0