def get_cluster_config_records()

in cookbooks/aws-parallelcluster-slurm/files/default/head_node_checks/common/ddb_utils.py [0:0]


def get_cluster_config_records(table_name: str, instance_ids: [str], region: str):
    ddb = boto_client("dynamodb", region_name=region)

    if not instance_ids:
        logger.warning("No instances to retrieve cluster config records for")
        return []

    item_ids = [CLUSTER_CONFIG_DDB_ID.format(instance_id=instance_id) for instance_id in instance_ids]
    requested_keys = [{"Id": {"S": item_id}} for item_id in item_ids]

    try:
        response = ddb.batch_get_item(RequestItems={table_name: {"Keys": requested_keys}})
        items = response.get("Responses", {}).get(table_name, [])
    except Exception as e:
        raise RuntimeError(f"Cannot read config versions due to DDB error: {e}")

    return items