def check_service_dependencies()

in templates/aws-cloudfront-waf/source/helper/helper.py [0:0]


def check_service_dependencies(log, resource_properties):
    log.debug("[check_service_dependencies] Start")

    unavailable_services = []
    SCOPE = os.getenv('SCOPE')
    waflib = WAFLIBv2()
    # ------------------------------------------------------------------------------------------------------------------
    # AWS WAF Resource TEST
    # ------------------------------------------------------------------------------------------------------------------
    try:
        waflib.list_web_acls(log, SCOPE)
    except botocore.exceptions.EndpointConnectionError:
        unavailable_services.append('AWS WAF')
    except Exception:
        log.debug("[check_service_dependencies] AWS WAF tested")

    # ------------------------------------------------------------------------------------------------------------------
    # Amazon Athena
    # ------------------------------------------------------------------------------------------------------------------
    if resource_properties['AthenaLogParser'] == "yes":
        try:
            athena_client = boto3.client('athena')
            athena_client.list_named_queries()
        except botocore.exceptions.EndpointConnectionError:
            unavailable_services.append('Amazon Athena')
        except Exception:
            log.debug("[check_service_dependencies] Amazon Athena tested")

    # ------------------------------------------------------------------------------------------------------------------
    # AWS Glue
    # ------------------------------------------------------------------------------------------------------------------
    if resource_properties['AthenaLogParser'] == "yes":
        try:
            glue_client = boto3.client('glue')
            glue_client.get_databases()
        except botocore.exceptions.EndpointConnectionError:
            unavailable_services.append('AWS Glue')
        except Exception:
            log.debug("[check_service_dependencies] AWS Glue")

    # ------------------------------------------------------------------------------------------------------------------
    # Amazon Kinesis Data Firehose
    # ------------------------------------------------------------------------------------------------------------------
    if resource_properties['HttpFloodProtectionLogParserActivated'] == "yes":
        try:
            firehose_client = boto3.client('firehose')
            firehose_client.list_delivery_streams()
        except botocore.exceptions.EndpointConnectionError:
            unavailable_services.append('Amazon Kinesis Data Firehose')
        except Exception:
            log.debug("[check_service_dependencies] Amazon Kinesis Data Firehose tested")

    if unavailable_services:
        raise Exception(
            "Failed to access the following service(s): %s. Please check if this region supports all required services: https://amzn.to/2SzWJXj" % '; '.join(
                unavailable_services))

    log.debug("[check_service_dependencies] End")