import { DynamoDB } from "aws-sdk" ; import * as _ from "lodash" ; const MAX_ITEMS = 25 ; export async function batchWrite ( documentClient , tableName , requests ) { try { return await Promise . all ( _ . chunk ( requests , MAX_ITEMS ) . map ( async ( chunk ) => { const res = await documentClient . batchWrite ( { RequestItems : { [ tableName ] : chunk , } , } ) . promise ( ) ; return res ; } ) ) ; } catch ( e ) { console . log ( `Dynamo-Types batchWrite - ${ JSON . stringify ( requests , null , 2 ) }` ) ; throw e ; } }