discoverInstances method

Future<DiscoverInstancesResponse> discoverInstances({
  1. required String namespaceName,
  2. required String serviceName,
  3. HealthStatusFilter? healthStatus,
  4. int? maxResults,
  5. Map<String, String>? optionalParameters,
  6. String? ownerAccount,
  7. Map<String, String>? queryParameters,
})

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.

May throw InvalidInput. May throw NamespaceNotFound. May throw RequestLimitExceeded. May throw ServiceNotFound.

Parameter 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.

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

Parameter healthStatus : 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.

Parameter maxResults : 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.

Parameter optionalParameters : 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.

Parameter ownerAccount : 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.

Parameter queryParameters : 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.

Implementation

Future<DiscoverInstancesResponse> discoverInstances({
  required String namespaceName,
  required String serviceName,
  HealthStatusFilter? healthStatus,
  int? maxResults,
  Map<String, String>? optionalParameters,
  String? ownerAccount,
  Map<String, String>? queryParameters,
}) async {
  _s.validateNumRange(
    'maxResults',
    maxResults,
    1,
    1000,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'Route53AutoNaming_v20170314.DiscoverInstances'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'NamespaceName': namespaceName,
      'ServiceName': serviceName,
      if (healthStatus != null) 'HealthStatus': healthStatus.value,
      if (maxResults != null) 'MaxResults': maxResults,
      if (optionalParameters != null)
        'OptionalParameters': optionalParameters,
      if (ownerAccount != null) 'OwnerAccount': ownerAccount,
      if (queryParameters != null) 'QueryParameters': queryParameters,
    },
  );

  return DiscoverInstancesResponse.fromJson(jsonResponse.body);
}