""" DynamoDB Client ============= Provides dynamodb_resource attribute for connection to AWS DynamDB service. https://aws.amazon.com/documentation/dynamodb/ """ import boto3 from botocore.client import Config dynamodb_resource = boto3.resource( 'dynamodb', 'us-east-1', config=Config(max_pool_connections=1000)) client = dynamodb_resource.meta.client ITEM_FIELD = 'Item' def batch_update_item_fields( table, key, verb, expressions, attribute_names, attribute_values, batch_size=4000, force=False): """Util to update several fields within an item.""" update_expression = '{} {}'.format(verb, ', '.join(expressions)) if not expressions or batch_size > len(update_expression) and not force: return False update_item = getattr(table, 'update_item') update_item( Key=key, UpdateExpression=update_expression, ExpressionAttributeNames=attribute_names, ExpressionAttributeValues=attribute_values) return True