(profile, region, tag)
return matching_tables
Using provided connection to dynamodb and tag, get all tables that have provided tag

    Profile provided and, if needed, used to build connection to STS.
Using provided connection to dynamodb and tag, get all tables that have provided tag
Using provided connection to dynamodb and tag get all tables that have provided tag
def get_table_name_by_tag(profile, region, tag):
    """
    Using provided connection to dynamodb and tag, get all tables that have provided tag

    Profile provided and, if needed, used to build connection to STS.
    """

    matching_tables = []
    all_tables = []
    sts = _get_aws_client(profile=profile, region=region, service="sts")
    dynamo = _get_aws_client(profile=profile, region=region, service="dynamodb")
    account_number = sts.get_caller_identity().get("Account")
    paginator = dynamo.get_paginator(operation_name="list_tables")
    tag_key = tag.split("=")[0]
    tag_value = tag.split("=")[1]

    get_all_tables = paginator.paginate()
    for page in get_all_tables:
        for table in page["TableNames"]:
            all_tables.append(table)
            logging.debug("Found table " + table)

    for table in all_tables:
        table_arn = "arn:aws:dynamodb:{}:{}:table/{}".format(
            region, account_number, table
        )
        table_tags = dynamo.list_tags_of_resource(ResourceArn=table_arn)
        for found_tag in table_tags["Tags"]:
            if found_tag["Key"] == tag_key:
                logging.debug("Checking table " + table + " tag " + found_tag["Key"])
                if found_tag["Value"] == tag_value:
                    matching_tables.append(table)
                    logging.info("Matched table " + table)

    return matching_tables
def get_table_name_by_tag ( profile , region , tag ) : matching_tables = [ ] all_tables = [ ] sts = _get_aws_client ( profile = profile , region = region , service = "sts" ) dynamo = _get_aws_client ( profile = profile , region = region , service = "dynamodb" ) account_number = sts . get_caller_identity ( ) . get ( "Account" ) paginator = dynamo . get_paginator ( operation_name = "list_tables" ) tag_key = tag . split ( "=" ) [ 0 ] tag_value = tag . split ( "=" ) [ 1 ] get_all_tables = paginator . paginate ( ) for page in get_all_tables : for table in page [ "TableNames" ] : all_tables . append ( table ) logging . debug ( "Found table " + table ) for table in all_tables : table_arn = "arn:aws:dynamodb:{}:{}:table/{}" . format ( region , account_number , table ) table_tags = dynamo . list_tags_of_resource ( ResourceArn = table_arn ) for found_tag in table_tags [ "Tags" ] : if found_tag [ "Key" ] == tag_key : logging . debug ( "Checking table " + table + " tag " + found_tag [ "Key" ] ) if found_tag [ "Value" ] == tag_value : matching_tables . append ( table ) logging . info ( "Matched table " + table ) return matching_tables