Batch request with unchecked failures Info

A batch request might return one or more failed items. To prevent data loss, make sure your code checks for failed items.

Detector ID
python/aws-unchecked-batch-failures@v1.0
Category
Common Weakness Enumeration (CWE) external icon

Noncompliant example

1def write_itemsin_batch_noncompliant(self, request_items):
2    import boto3
3    self.dynamodb = boto3.client('dynamodb')
4    batch_list = self.dynamodb_conn.new_batch_write_list()
5    batch_list.add_batch(dynamodb_table, puts=items)
6    response = self.dynamodb_conn.batch_write_item(batch_list)
7    # Noncompliant: unprocessed items not checked.
8    return response

Compliant example

1def write_itemsin_batch_compliant(self, request_items):
2    import boto3
3    self.dynamodb = boto3.client('dynamodb')
4    batch_list = self.dynamodb_conn.new_batch_write_list()
5    batch_list.add_batch(dynamodb_table, puts=items)
6    response = self.dynamodb_conn.batch_write_item(batch_list)
7    # Compliant: has checks for unprocessed items.
8    unprocessed = response.get('UnprocessedItems', None)
9    return response, unprocessed