Search code examples
google-cloud-vertex-ai

How to properly extract endpoint id from gcp_resources of a Vertex AI pipeline on GCP?


I am using GCP Vertex AI pipeline (KFP) and using google-cloud-aiplatform==1.10.0, kfp==1.8.11, google-cloud-pipeline-components==0.2.6 In a component I am getting a gcp_resources documentation :

gcp_resources (str):
            Serialized gcp_resources proto tracking the create endpoint's long running operation.

To extract the endpoint_id to do online prediction of my deployed model, I am doing:

from google_cloud_pipeline_components.proto.gcp_resources_pb2 import GcpResources
from google.protobuf.json_format import Parse
input_gcp_resources = Parse(endpoint_ressource_name, GcpResources())
gcp_resources=input_gcp_resources.resources.__getitem__(0).resource_uri.split('/')
endpoint_id=gcp_resources[gcp_resources.index('endpoints')+1]

Is there a better/native way of extracting such info ?


Solution

  • In this case is the best way to extract the information. But, I recommend using the yarl library for complex uri to parse.

    You can see this example:

    >>> from yarl import URL
    >>> url = URL('https://www.python.org/~guido?arg=1#frag')
    >>> url
    URL('https://www.python.org/~guido?arg=1#frag')
    

    All URL parts can be accessed by these properties.

    >>> url.scheme
    'https'
    >>> url.host
    'www.python.org'
    >>> url.path
    '/~guido'
    >>> url.query_string
    'arg=1'
    >>> url.query
    <MultiDictProxy('arg': '1')>
    >>> url.fragment
    'frag'