Skip to content

discover_instances async

discover_instances(
    namespace_name: NamespaceName,
    service_name: ServiceName,
    *,
    config_overrides: Optional[AsyncServiceDiscoveryClientConfig] = None,
    max_results: Optional[DiscoverMaxResults] = None,
    query_parameters: Optional[Attributes] = None,
    optional_parameters: Optional[Attributes] = None,
    health_status: Optional[HealthStatusFilter] = None,
    owner_account: Optional[AWSAccountId] = None,
) -> DiscoverInstancesResponse

Discovers registered instances for a specified namespace and service. You can use DiscoverInstances to discover instances for any type of namespace. DiscoverInstances returns a randomized list of instances allowing customers to distribute traffic evenly across instances. For public and private DNS namespaces, you can also use DNS queries to discover instances.

Parameters:

  • namespace_name (NamespaceName) –

    The HttpName name of the namespace. The HttpName is found in the HttpProperties member of the Properties member of the namespace. In most cases, Name and HttpName match. However, if you reuse Name for namespace creation, a generated hash is added to HttpName to distinguish the two.

  • service_name (ServiceName) –

    The name of the service that you specified when you registered the instance.

  • max_results (Optional[DiscoverMaxResults], default: None ) –

    The maximum number of instances that you want Cloud Map to return in the response to a DiscoverInstances request. If you don't specify a value for MaxResults, Cloud Map returns up to 100 instances.

  • query_parameters (Optional[Attributes], default: None ) –

    Filters to scope the results based on custom attributes for the instance (for example, {version=v1, az=1a}). Only instances that match all the specified key-value pairs are returned.

  • optional_parameters (Optional[Attributes], default: None ) –

    Opportunistic filters to scope the results based on custom attributes. If there are instances that match both the filters specified in both the QueryParameters parameter and this parameter, all of these instances are returned. Otherwise, the filters are ignored, and only instances that match the filters that are specified in the QueryParameters parameter are returned.

  • health_status (Optional[HealthStatusFilter], default: None ) –

    The health status of the instances that you want to discover. This parameter is ignored for services that don't have a health check configured, and all instances are returned.

    HEALTHY

    Returns healthy instances.

    UNHEALTHY

    Returns unhealthy instances.

    ALL

    Returns all instances.

    HEALTHY_OR_ELSE_ALL

    Returns healthy instances, unless none are reporting a healthy state. In that case, return all instances. This is also called failing open.

  • owner_account (Optional[AWSAccountId], default: None ) –

    The ID of the Amazon Web Services account that owns the namespace associated with the instance, as specified in the namespace ResourceOwner field. For instances associated with namespaces that are shared with your account, you must specify an OwnerAccount.

Raises:

  • InvalidInput –

    One or more specified values aren't valid. For example, a required value might be missing, a numeric value might be outside the allowed range, or a string value might exceed length constraints.

  • NamespaceNotFound –

    No namespace exists with the specified ID.

  • RequestLimitExceeded –

    The operation can't be completed because you've reached the quota for the number of requests. For more information, see Cloud Map API request throttling quota in the Cloud Map Developer Guide.

  • ServiceNotFound –

    No service exists with the specified ID.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

Discover instances using owner account Discovers instances in a shared namespace by specifying the OwnerAccount parameter, useful when working with shared namespaces.

>>> await client.discover_instances(namespace_name='example-shared-namespace', service_name='shared-namespace-service', owner_account='123456789012')
Example: Discover registered instances
Example: Discover registered instances
>>> await client.discover_instances(namespace_name='example.com', service_name='myservice', max_results=10, health_status='ALL')
Source code in docs_src/capo_servicediscovery/_services/async_service_discovery.py
async def discover_instances(
    self,
    namespace_name: "capo_servicediscovery.types.namespace_name.NamespaceName",
    service_name: "capo_servicediscovery.types.service_name.ServiceName",
    *,
    config_overrides: Optional[AsyncServiceDiscoveryClientConfig] = None,
    max_results: Optional[
        "capo_servicediscovery.types.discover_max_results.DiscoverMaxResults"
    ] = None,
    query_parameters: Optional[
        "capo_servicediscovery.types.attributes.Attributes"
    ] = None,
    optional_parameters: Optional[
        "capo_servicediscovery.types.attributes.Attributes"
    ] = None,
    health_status: Optional[
        "capo_servicediscovery.types.health_status_filter.HealthStatusFilter"
    ] = None,
    owner_account: Optional[
        "capo_servicediscovery.types.aws_account_id.AWSAccountId"
    ] = None,
) -> "capo_servicediscovery.types.discover_instances_response.DiscoverInstancesResponse":
    """<p>Discovers registered instances for a specified namespace and service. You can use <code>DiscoverInstances</code> to discover instances for any type of namespace. <code>DiscoverInstances</code> returns a randomized list of instances allowing customers to distribute traffic evenly across instances. For public and private DNS namespaces, you can also use DNS queries to discover instances.</p>

    Args:
        namespace_name: <p>The <code>HttpName</code> name of the namespace. The <code>HttpName</code> is found in the <code>HttpProperties</code> member of the <code>Properties</code> member of the namespace. In most cases, <code>Name</code> and <code>HttpName</code> match. However, if you reuse <code>Name</code> for namespace creation, a generated hash is added to <code>HttpName</code> to distinguish the two.</p>
        service_name: <p>The name of the service that you specified when you registered the instance.</p>
        max_results: <p>The maximum number of instances that you want Cloud Map to return in the response to a <code>DiscoverInstances</code> request. If you don't specify a value for <code>MaxResults</code>, Cloud Map returns up to 100 instances.</p>
        query_parameters: <p>Filters to scope the results based on custom attributes for the instance (for example, <code>{version=v1, az=1a}</code>). Only instances that match all the specified key-value pairs are returned.</p>
        optional_parameters: <p>Opportunistic filters to scope the results based on custom attributes. If there are instances that match both the filters specified in both the <code>QueryParameters</code> parameter and this parameter, all of these instances are returned. Otherwise, the filters are ignored, and only instances that match the filters that are specified in the <code>QueryParameters</code> parameter are returned.</p>
        health_status: <p>The health status of the instances that you want to discover. This parameter is ignored for services that don't have a health check configured, and all instances are returned.</p> <dl> <dt>HEALTHY</dt> <dd> <p>Returns healthy instances.</p> </dd> <dt>UNHEALTHY</dt> <dd> <p>Returns unhealthy instances.</p> </dd> <dt>ALL</dt> <dd> <p>Returns all instances.</p> </dd> <dt>HEALTHY_OR_ELSE_ALL</dt> <dd> <p>Returns healthy instances, unless none are reporting a healthy state. In that case, return all instances. This is also called failing open.</p> </dd> </dl>
        owner_account: <p>The ID of the Amazon Web Services account that owns the namespace associated with the instance, as specified in the namespace <code>ResourceOwner</code> field. For instances associated with namespaces that are shared with your account, you must specify an <code>OwnerAccount</code>.</p>

    Raises:
        capo_servicediscovery.errors.invalid_input.InvalidInput: <p>One or more specified values aren't valid. For example, a required value might be missing, a numeric value might be outside the allowed range, or a string value might exceed length constraints.</p>
        capo_servicediscovery.errors.namespace_not_found.NamespaceNotFound: <p>No namespace exists with the specified ID.</p>
        capo_servicediscovery.errors.request_limit_exceeded.RequestLimitExceeded: <p>The operation can't be completed because you've reached the quota for the number of requests. For more information, see <a href="https://docs.aws.amazon.com/cloud-map/latest/dg/throttling.html">Cloud Map API request throttling quota</a> in the <i>Cloud Map Developer Guide</i>.</p>
        capo_servicediscovery.errors.service_not_found.ServiceNotFound: <p>No service exists with the specified ID.</p>
        capo_servicediscovery.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        Discover instances using owner account
        Discovers instances in a shared namespace by specifying the OwnerAccount parameter, useful when working with shared namespaces.

        >>> await client.discover_instances(namespace_name='example-shared-namespace', service_name='shared-namespace-service', owner_account='123456789012')
        Example: Discover registered instances
        Example: Discover registered instances

        >>> await client.discover_instances(namespace_name='example.com', service_name='myservice', max_results=10, health_status='ALL')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_servicediscovery.types.discover_instances_request.DiscoverInstancesRequest]",
    ) -> AsyncOperationResponse[
        "capo_servicediscovery.types.discover_instances_response.DiscoverInstancesResponse"
    ]:
        import capo_servicediscovery._operations.route53_auto_naming_v20170314.discover_instances

        (
            output,
            http_response,
        ) = await capo_servicediscovery._operations.route53_auto_naming_v20170314.discover_instances.async_discover_instances(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("DiscoverInstances")
    )
    input_: capo_servicediscovery.types.discover_instances_request.DiscoverInstancesRequest = {
        "namespace_name": namespace_name,
        "service_name": service_name,
    }
    if max_results is not None:
        input_["max_results"] = max_results
    if query_parameters is not None:
        input_["query_parameters"] = query_parameters
    if optional_parameters is not None:
        input_["optional_parameters"] = optional_parameters
    if health_status is not None:
        input_["health_status"] = health_status
    if owner_account is not None:
        input_["owner_account"] = owner_account

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output