Search in sources :

Example 1 with DiscoverInstancesResult

use of com.amazonaws.services.servicediscovery.model.DiscoverInstancesResult in project aws-doc-sdk-examples by awsdocs.

the class DiscoverInstances method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "To run this example, supply the Namespacename , ServiceName of aws cloud map!\n" + "\n" + "Ex: DiscoverInstances <namespace-name> <service-name> \n";
    if (args.length < 2) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String namespace_name = args[0];
    String service_name = args[1];
    AWSCredentials credentials = null;
    try {
        credentials = new EnvironmentVariableCredentialsProvider().getCredentials();
    } catch (Exception e) {
        throw new AmazonClientException("Cannot Load Credentials");
    }
    System.out.format("Instances in AWS cloud map %s:\n", namespace_name);
    AWSServiceDiscovery client = AWSServiceDiscoveryClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials)).withRegion(System.getenv("AWS_REGION")).build();
    DiscoverInstancesRequest request = new DiscoverInstancesRequest();
    request.setNamespaceName(namespace_name);
    request.setServiceName(service_name);
    DiscoverInstancesResult result = client.discoverInstances(request);
    System.out.println(result.toString());
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) EnvironmentVariableCredentialsProvider(com.amazonaws.auth.EnvironmentVariableCredentialsProvider) DiscoverInstancesResult(com.amazonaws.services.servicediscovery.model.DiscoverInstancesResult) AWSServiceDiscovery(com.amazonaws.services.servicediscovery.AWSServiceDiscovery) AmazonClientException(com.amazonaws.AmazonClientException) DiscoverInstancesRequest(com.amazonaws.services.servicediscovery.model.DiscoverInstancesRequest) AWSCredentials(com.amazonaws.auth.AWSCredentials) AmazonClientException(com.amazonaws.AmazonClientException)

Aggregations

AmazonClientException (com.amazonaws.AmazonClientException)1 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)1 EnvironmentVariableCredentialsProvider (com.amazonaws.auth.EnvironmentVariableCredentialsProvider)1 AWSServiceDiscovery (com.amazonaws.services.servicediscovery.AWSServiceDiscovery)1 DiscoverInstancesRequest (com.amazonaws.services.servicediscovery.model.DiscoverInstancesRequest)1 DiscoverInstancesResult (com.amazonaws.services.servicediscovery.model.DiscoverInstancesResult)1