def get_appsync_endpoint()

in cloudformation/custom_resources/getAppSyncEndpoint/custom_resource.py [0:0]


def get_appsync_endpoint(appId):
    backend_cfn = amplify.get_backend_environment(appId=appId, environmentName="main")[
        "backendEnvironment"
    ]["stackName"]

    cfn_resources = cfn.describe_stack_resources(StackName=backend_cfn)[
        "StackResources"
    ]

    api_cfn_arn = [
        x["PhysicalResourceId"]
        for x in cfn_resources
        if "api" in x["LogicalResourceId"]
    ][0]

    api_cfn_outputs = cfn.describe_stacks(StackName=api_cfn_arn)["Stacks"][0]["Outputs"]

    gql_endpoint = next(
        (
            item["OutputValue"]
            for item in api_cfn_outputs
            if item["OutputKey"] == "GraphQLAPIEndpointOutput"
        ),
        None,
    )

    helper.Data["endpoint"] = gql_endpoint