Skip to content

/AWS1/CL_SDY=>DISCOVERINSTANCES()

About DiscoverInstances

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.

Method Signature

IMPORTING

Required arguments:

iv_namespacename TYPE /AWS1/SDYNAMESPACENAME /AWS1/SDYNAMESPACENAME

The HttpName name of the namespace. It's 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.

iv_servicename TYPE /AWS1/SDYSERVICENAME /AWS1/SDYSERVICENAME

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

Optional arguments:

iv_maxresults TYPE /AWS1/SDYDISCOVERMAXRESULTS /AWS1/SDYDISCOVERMAXRESULTS

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.

it_queryparameters TYPE /AWS1/CL_SDYATTRIBUTES_W=>TT_ATTRIBUTES TT_ATTRIBUTES

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.

it_optionalparameters TYPE /AWS1/CL_SDYATTRIBUTES_W=>TT_ATTRIBUTES TT_ATTRIBUTES

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.

iv_healthstatus TYPE /AWS1/SDYHEALTHSTATUSFILTER /AWS1/SDYHEALTHSTATUSFILTER

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.

RETURNING

oo_output TYPE REF TO /aws1/cl_sdydiscoverinstsrsp /AWS1/CL_SDYDISCOVERINSTSRSP

Domain /AWS1/RT_ACCOUNT_ID
Primitive Type NUMC

Examples

Syntax Example

This is an example of the syntax for calling the method. It includes every possible argument and initializes every possible value. The data provided is not necessarily semantically accurate (for example the value "string" may be provided for something that is intended to be an instance ID, or in some cases two arguments may be mutually exclusive). The syntax shows the ABAP syntax for creating the various data structures.

DATA(lo_result) = lo_client->/aws1/if_sdy~discoverinstances(
  it_optionalparameters = VALUE /aws1/cl_sdyattributes_w=>tt_attributes(
    (
      VALUE /aws1/cl_sdyattributes_w=>ts_attributes_maprow(
        key = |string|
        value = new /aws1/cl_sdyattributes_w( |string| )
      )
    )
  )
  it_queryparameters = VALUE /aws1/cl_sdyattributes_w=>tt_attributes(
    (
      VALUE /aws1/cl_sdyattributes_w=>ts_attributes_maprow(
        key = |string|
        value = new /aws1/cl_sdyattributes_w( |string| )
      )
    )
  )
  iv_healthstatus = |string|
  iv_maxresults = 123
  iv_namespacename = |string|
  iv_servicename = |string|
).

This is an example of reading all possible response values

LOOP AT lo_result->get_instances( ) into lo_row.
  lv_resourceid = lo_row_1->get_instanceid( ).
  lv_namespacenamehttp = lo_row_1->get_namespacename( ).
  lv_servicename = lo_row_1->get_servicename( ).
  lv_healthstatus = lo_row_1->get_healthstatus( ).
  LOOP AT lo_row_1->get_attributes( ) into ls_row_2.
    lv_key = ls_row_2-key.
    lv_attrvalue = lo_value->get_value( ).
  ENDLOOP.
ENDLOOP.
lv_revision = lo_result->get_instancesrevision( ).

Example: Discover registered instances

Example: Discover registered instances

DATA(lo_result) = lo_client->/aws1/if_sdy~discoverinstances(
  iv_healthstatus = |ALL|
  iv_maxresults = 10
  iv_namespacename = |example.com|
  iv_servicename = |myservice|
).