in iot-onboarding-service/src/cloudrack-lambda-core/db/db.go [238:290]
func (dbc DBConfig) DeleteMany(data interface{}) error {
//Dynamo db currently limits batches to 25 items
batches := core.Chunk(InterfaceSlice(data), 25)
for i, dataArray := range batches {
log.Printf("DB> Batch %i deleting: %+v", i, dataArray)
items := make([]*dynamodb.WriteRequest, len(dataArray), len(dataArray))
for i, item := range dataArray {
av, err := dynamodbattribute.MarshalMap(item)
if err != nil {
fmt.Println("Got error marshalling new property item:")
fmt.Println(err.Error())
}
items[i] = &dynamodb.WriteRequest{
DeleteRequest: &dynamodb.DeleteRequest{
Key: av,
},
}
}
bwii := &dynamodb.BatchWriteItemInput{
RequestItems: map[string][]*dynamodb.WriteRequest{
dbc.TableName: items,
},
}
_, err := dbc.DbService.BatchWriteItem(bwii)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case dynamodb.ErrCodeProvisionedThroughputExceededException:
fmt.Println(dynamodb.ErrCodeProvisionedThroughputExceededException, aerr.Error())
case dynamodb.ErrCodeResourceNotFoundException:
fmt.Println(dynamodb.ErrCodeResourceNotFoundException, aerr.Error())
case dynamodb.ErrCodeItemCollectionSizeLimitExceededException:
fmt.Println(dynamodb.ErrCodeItemCollectionSizeLimitExceededException, aerr.Error())
case dynamodb.ErrCodeRequestLimitExceeded:
fmt.Println(dynamodb.ErrCodeRequestLimitExceeded, aerr.Error())
case dynamodb.ErrCodeInternalServerError:
fmt.Println(dynamodb.ErrCodeInternalServerError, aerr.Error())
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
}
return err
}
}
return nil
}