in syndicate/connection/dynamo_connection.py [0:0]
def update_table_capacity(self, table_name, existing_capacity_mode,
read_capacity, write_capacity,
existing_read_capacity, existing_write_capacity,
existing_global_indexes, wait=True):
""" Updates table capacity configuration. If both read_capacity and
write capacity are provided in the deployment_resources.json
sets their values for the table if it has PROVISIONED billing mode, if
it is in the PAY_PER_REQUEST mode, the table is set to PROVISIONED with
specified capacity values. If the capacity attributes are omitted and
the table is in the PROVISIONED mode it is set to the PAY_PER_REQUEST.
:param table_name: DynamoDB table name
:type table_name: str
:param existing_capacity_mode: capacity mode currently set in the table
:type existing_capacity_mode: str
:param read_capacity: read capacity to assign for the table
:type read_capacity: int
:param write_capacity: write capacity to assign for the table
:type write_capacity: int
:param existing_read_capacity: read capacity currently set in the table
:type existing_read_capacity: int
:param existing_write_capacity: write capacity currently set
in the table
:type existing_write_capacity: int
:param existing_global_indexes: global secondary indexes already
present in the table
:type existing_global_indexes: list
:param wait: to wait for table update to finish or not
:type wait: bool
:returns update_table response as boto3.DynamoDB.Table object or None
if there were no changes made
"""
params = {}
if read_capacity and write_capacity:
if existing_capacity_mode == 'PROVISIONED':
if read_capacity != existing_read_capacity \
or write_capacity != existing_write_capacity:
params['ProvisionedThroughput'] = dict(
ReadCapacityUnits=read_capacity,
WriteCapacityUnits=write_capacity)
elif existing_capacity_mode == 'PAY_PER_REQUEST':
params['BillingMode'] = 'PROVISIONED'
params['ProvisionedThroughput'] = dict(
ReadCapacityUnits=read_capacity,
WriteCapacityUnits=write_capacity)
global_secondary_indexes_updates = []
for gsi in existing_global_indexes:
gsi_read_capacity = \
gsi.get('ProvisionedThroughput', {}).get(
'ReadCapacityUnits') or read_capacity
gsi_write_capacity = \
gsi.get('ProvisionedThroughput', {}
).get('WriteCapacityUnits') or write_capacity
global_secondary_indexes_updates.append({
'Update': {
'IndexName': gsi.get('IndexName'),
'ProvisionedThroughput': {
'ReadCapacityUnits': gsi_read_capacity,
'WriteCapacityUnits': gsi_write_capacity
}
}
})
params['GlobalSecondaryIndexUpdates'] = \
global_secondary_indexes_updates
else:
if existing_capacity_mode == 'PROVISIONED':
params['BillingMode'] = 'PAY_PER_REQUEST'
if params:
params.update(dict(TableName=table_name))
_LOG.debug(f'Updating {table_name} table capacity. Table capacity '
f'mode: {existing_capacity_mode}, meta read/write '
f'capacities: {read_capacity}/{write_capacity}, existing '
f'read/write capacities: {existing_read_capacity}/'
f'{existing_write_capacity}. Update params: {params}')
self.client.update_table(**params)
if wait:
self._wait_for_table_update(table_name=table_name)
return self.get_table_by_name(table_name)