def get_config()

in source/lambda/capture_news_feed/util/ddb_helper.py [0:0]


def get_config(dynamodb=None, **scan_kwargs):
    """ This method retrieves configuration list from DDB which are "enabled = True" """
    if not dynamodb:
        dynamodb = service_helper.get_service_resource("dynamodb")

    table = dynamodb.Table(os.environ["DDB_CONFIG_TABLE_NAME"])

    config_list = []
    start_key = None
    done = False

    while not done:
        scan_kwargs["FilterExpression"] = Attr("enabled").eq(True)
        if start_key:
            scan_kwargs["ExclusiveStartKey"] = start_key

        # scan all the config in the dynamodb table and filter records with enabled=false
        response = table.scan(**scan_kwargs)
        config_list.extend(response["Items"])

        # if "LastEvaluatedKey" is not part of the respose then do not pagingate. Hence exit the loop
        start_key = response.get("LastEvaluatedKey", None)
        done = start_key is None

    logger.debug(f"Dumping config_list: {config_list}")
    return config_list