I am using aws lambda that gets a list of items and it pushes items in the table asynchronously. Here promise.all(promiseList) does not add the data in the table but doing promise.all(promiseList[0]) ensures that my first element is pushed in the table. How can I make it to wait for all? My code-
let promiseList = [];
// await Promise.all(
promiseList.push(
event.Records.map(async record => {
console.log(record.dynamodb.Keys.ServiceOrderId.S);
console.log('Inside initiate payment');
const paymentObject = {
paymentId: record.dynamodb.Keys.ServiceOrderId.S,
totalAmount: "1200"
};
console.log(paymentObject);
const dynamoDBParams = {
TableName : TABLE_NAME,
Item : paymentObject
};
return await DynamoDBClient.put(dynamoDBParams).promise();
}
)
);
return await Promise.all(promiseList[0]);