0

我目前正在使用 dynamoose 来管理 dynamodb 中的记录。

从我的客户那里,我收到了一组内部人员

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

我的 lambda 函数通过变量接收集合insiders,并在每个记录中循环。内部循环我更新记录的位置

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();
    }
  }
}

当我在本地对其进行测试时,这工作正常,但是当我将其部署到 AWS Lambda 时,它没有被更新。我也把console.log里面循环,我得到打印的日志。

4

0 回答 0