def get_provisioned_write_units(table_name): """ Returns the number of provisioned write units for the table :type table_name: str :param table_name: Name of the DynamoDB table :returns: int -- Number of write units """ table = dynamodb.get_table(table_name) logger.debug('{0} - Provisioned write units: {1:d}'.format( table_name, table.write_units)) return int(table.write_units)
def get_provisioned_write_units(table_name): """ Returns the number of provisioned write units for the table :type table_name: str :param table_name: Name of the DynamoDB table :returns: int -- Number of write units """ try: table = dynamodb.get_table(table_name) except DynamoDBResponseError: # Return if the table does not exist return None logger.debug('{0} - Provisioned write units: {1:d}'.format( table_name, table.write_units)) return int(table.write_units)
def main(): region="eu-west-1" con = dynamodb.connect_dynamodb(region) table = dynamodb.get_table(con, "testingc") print table the_item = dynamodb.get_item(table, 1) print the_item item_attrs = {} item_attrs['length'] = 177 item_attrs['name'] = "kerst" item_attrs['lastname'] = "man" item_attrs['city'] = "zuidpool" result = dynamodb.set_item(table, 5, item_attrs) print result
def update_throughput(table_name, read_units, write_units, key_name): """ Update throughput on the DynamoDB table :type table_name: str :param table_name: Name of the DynamoDB table :type read_units: int :param read_units: New read unit provisioning :type write_units: int :param write_units: New write unit provisioning :type key_name: str :param key_name: Configuration option key name """ table = dynamodb.get_table(table_name) # Check that we are in the right time frame if get_table_option(key_name, 'maintenance_windows'): if not __is_maintenance_window(table_name, get_table_option(key_name, 'maintenance_windows')): logger.warning( '{0} - Current time is outside maintenance window'.format( table_name)) return else: logger.info( '{0} - Current time is within maintenance window'.format( table_name)) # Check table status if table.status != 'ACTIVE': logger.warning( '{0} - Not performing throughput changes when table ' 'is in {1} state'.format(table_name, table.status)) # If this setting is True, we will only scale down when # BOTH reads AND writes are low if get_table_option(key_name, 'always_decrease_rw_together'): if (read_units < table.read_units) or (table.read_units == get_table_option(key_name, 'min_provisioned_reads')): if (write_units < table.write_units) or (table.write_units == get_table_option(key_name, 'min_provisioned_writes')): logger.info( '{0} - Both reads and writes will be decreased'.format( table_name)) elif read_units < table.read_units: logger.info( '{0} - Will not decrease reads nor writes, waiting for ' 'both to become low before decrease'.format(table_name)) read_units = table.read_units elif write_units < table.write_units: logger.info( '{0} - Will not decrease reads nor writes, waiting for ' 'both to become low before decrease'.format(table_name)) write_units = table.write_units if read_units == table.read_units and write_units == table.write_units: logger.debug('{0} - No need to update provisioning') return if not get_global_option('dry_run'): try: table.update_throughput(int(read_units), int(write_units)) logger.info('Provisioning updated') except DynamoDBResponseError as error: dynamodb_error = error.body['__type'].rsplit('#', 1)[1] if dynamodb_error == 'LimitExceededException': logger.warning( '{0} - {1}'.format(table_name, error.body['message'])) if int(read_units) > table.read_units: logger.info('{0} - Scaling up reads to {1:d}'.format( table_name, int(read_units))) update_throughput( table_name, int(read_units), int(table.write_units), key_name) elif int(write_units) > table.write_units: logger.info('{0} - Scaling up writes to {1:d}'.format( table_name, int(write_units))) update_throughput( table_name, int(table.read_units), int(write_units), key_name) elif dynamodb_error == 'ValidationException': logger.warning('{0} - ValidationException: {1}'.format( table_name, error.body['message'])) elif dynamodb_error == 'ResourceInUseException': logger.warning('{0} - ResourceInUseException: {1}'.format( table_name, error.body['message'])) elif dynamodb_error == 'AccessDeniedException': logger.warning('{0} - AccessDeniedException: {1}'.format( table_name, error.body['message'])) else: logger.error( ( '{0} - Unhandled exception: {1}: {2}. ' 'Please file a bug report at ' 'https://github.com/sebdah/dynamic-dynamodb/issues' ).format( table_name, dynamodb_error, error.body['message']))