(dynamo, table_name, billing_mode)
Empty table named table_name
Empty table named table_name
Empty table named table_name
def do_empty(dynamo, table_name, billing_mode):
    """
    Empty table named table_name
    """

    logging.info("Starting Empty for " + table_name + "..")

    # get table schema
    logging.info("Fetching table schema for " + table_name)
    table_data = dynamo.describe_table(TableName=table_name)

    table_desc = table_data["Table"]
    table_attribute_definitions = table_desc["AttributeDefinitions"]
    table_key_schema = table_desc["KeySchema"]
    original_read_capacity = table_desc["ProvisionedThroughput"]["ReadCapacityUnits"]
    original_write_capacity = table_desc["ProvisionedThroughput"]["WriteCapacityUnits"]
    table_local_secondary_indexes = table_desc.get("LocalSecondaryIndexes")
    table_global_secondary_indexes = table_desc.get("GlobalSecondaryIndexes")

    optional_args = {}
    if billing_mode == PROVISIONED_BILLING_MODE:
        table_provisioned_throughput = {
            "ReadCapacityUnits": int(original_read_capacity),
            "WriteCapacityUnits": int(original_write_capacity),
        }
        optional_args["ProvisionedThroughput"] = table_provisioned_throughput

    if table_local_secondary_indexes is not None:
        optional_args["LocalSecondaryIndexes"] = table_local_secondary_indexes

    if table_global_secondary_indexes is not None:
        optional_args["GlobalSecondaryIndexes"] = table_global_secondary_indexes

    table_provisioned_throughput = {
        "ReadCapacityUnits": int(original_read_capacity),
        "WriteCapacityUnits": int(original_write_capacity),
    }

    logging.info("Deleting Table " + table_name)

    delete_table(dynamo, sleep_interval, table_name)

    logging.info("Creating Table " + table_name)

    while True:
        try:
            dynamo.create_table(
                AttributeDefinitions=table_attribute_definitions,
                TableName=table_name,
                KeySchema=table_key_schema,
                BillingMode=billing_mode,
                **optional_args
            )
            break
        except dynamo.exceptions.LimitExceededException:
            logging.info("Limit exceeded, retrying creation of " + table_name + "..")
            time.sleep(sleep_interval)
        except dynamo.exceptions.ProvisionedThroughputExceededException:
            logging.info(
                "Control plane limit exceeded, retrying creation of "
                + table_name
                + ".."
            )
            time.sleep(sleep_interval)
        except dynamo.exceptions.ClientError as e:
            logging.exception(e)
            sys.exit(1)

    # wait for table creation completion
    wait_for_active_table(dynamo, table_name, "created")

    logging.info(
        "Recreation of "
        + table_name
        + " completed. Time taken: "
        + str(datetime.datetime.now().replace(microsecond=0) - start_time)
    )
def do_empty ( dynamo , table_name , billing_mode ) : logging . info ( "Starting Empty for " + table_name + ".." ) # get table schema logging . info ( "Fetching table schema for " + table_name ) table_data = dynamo . describe_table ( TableName = table_name ) table_desc = table_data [ "Table" ] table_attribute_definitions = table_desc [ "AttributeDefinitions" ] table_key_schema = table_desc [ "KeySchema" ] original_read_capacity = table_desc [ "ProvisionedThroughput" ] [ "ReadCapacityUnits" ] original_write_capacity = table_desc [ "ProvisionedThroughput" ] [ "WriteCapacityUnits" ] table_local_secondary_indexes = table_desc . get ( "LocalSecondaryIndexes" ) table_global_secondary_indexes = table_desc . get ( "GlobalSecondaryIndexes" ) optional_args = { } if billing_mode == PROVISIONED_BILLING_MODE : table_provisioned_throughput = { "ReadCapacityUnits" : int ( original_read_capacity ) , "WriteCapacityUnits" : int ( original_write_capacity ) , } optional_args [ "ProvisionedThroughput" ] = table_provisioned_throughput if table_local_secondary_indexes is not None : optional_args [ "LocalSecondaryIndexes" ] = table_local_secondary_indexes if table_global_secondary_indexes is not None : optional_args [ "GlobalSecondaryIndexes" ] = table_global_secondary_indexes table_provisioned_throughput = { "ReadCapacityUnits" : int ( original_read_capacity ) , "WriteCapacityUnits" : int ( original_write_capacity ) , } logging . info ( "Deleting Table " + table_name ) delete_table ( dynamo , sleep_interval , table_name ) logging . info ( "Creating Table " + table_name ) while True : try : dynamo . create_table ( AttributeDefinitions = table_attribute_definitions , TableName = table_name , KeySchema = table_key_schema , BillingMode = billing_mode , * * optional_args ) break except dynamo . exceptions . LimitExceededException : logging . info ( "Limit exceeded, retrying creation of " + table_name + ".." ) time . sleep ( sleep_interval ) except dynamo . exceptions . ProvisionedThroughputExceededException : logging . info ( "Control plane limit exceeded, retrying creation of " + table_name + ".." ) time . sleep ( sleep_interval ) except dynamo . exceptions . ClientError as e : logging . exception ( e ) sys . exit ( 1 ) # wait for table creation completion wait_for_active_table ( dynamo , table_name , "created" ) logging . info ( "Recreation of " + table_name + " completed. Time taken: " + str ( datetime . datetime . now ( ) . replace ( microsecond = 0 ) - start_time ) )