Search in sources :

Example 1 with AWSServiceDiscovery

use of com.amazonaws.services.servicediscovery.AWSServiceDiscovery 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)

Example 2 with AWSServiceDiscovery

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

the class CreateService method main.

public static void main(String[] args) throws Exception {
    AWSCredentials credentials = null;
    try {
        credentials = new ProfileCredentialsProvider().getCredentials();
    } catch (Exception e) {
        throw new AmazonClientException("Cannot Load credentials");
    }
    AWSServiceDiscovery client = AWSServiceDiscoveryClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials)).withRegion("us-east-1").build();
    CreateServiceRequest crequest = new CreateServiceRequest();
    crequest.setName("example-service-01");
    crequest.setDescription("This is an example service request");
    // Replace with the namespaceID
    crequest.setNamespaceId("ns-ldmexc5fqajjnhco");
    System.out.println(client.createService(crequest));
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) CreateServiceRequest(com.amazonaws.services.servicediscovery.model.CreateServiceRequest) AWSServiceDiscovery(com.amazonaws.services.servicediscovery.AWSServiceDiscovery) AmazonClientException(com.amazonaws.AmazonClientException) ProfileCredentialsProvider(com.amazonaws.auth.profile.ProfileCredentialsProvider) AWSCredentials(com.amazonaws.auth.AWSCredentials) AmazonClientException(com.amazonaws.AmazonClientException)

Example 3 with AWSServiceDiscovery

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

the class ListInstances method main.

public static void main(String[] args) throws Exception {
    AWSCredentials credentials = null;
    try {
        credentials = new ProfileCredentialsProvider().getCredentials();
    } catch (Exception e) {
        throw new AmazonClientException("Cannot Load credentials");
    }
    AWSServiceDiscovery client = AWSServiceDiscoveryClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials)).withRegion("us-east-1").build();
    ListInstancesRequest lreq = new ListInstancesRequest();
    // Replace with service id
    lreq.setServiceId("srv-l7gkxmjapm5givba");
    System.out.println(client.listInstances(lreq));
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AWSServiceDiscovery(com.amazonaws.services.servicediscovery.AWSServiceDiscovery) ListInstancesRequest(com.amazonaws.services.servicediscovery.model.ListInstancesRequest) AmazonClientException(com.amazonaws.AmazonClientException) ProfileCredentialsProvider(com.amazonaws.auth.profile.ProfileCredentialsProvider) AWSCredentials(com.amazonaws.auth.AWSCredentials) AmazonClientException(com.amazonaws.AmazonClientException)

Example 4 with AWSServiceDiscovery

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

the class LookUpServicewithFilter method main.

public static void main(String[] args) throws Exception {
    AWSCredentials credentials = null;
    try {
        credentials = new ProfileCredentialsProvider().getCredentials();
    } catch (Exception e) {
        throw new AmazonClientException("Cannot Load credentials");
    }
    AWSServiceDiscovery client = AWSServiceDiscoveryClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials)).withRegion("us-east-1").build();
    DiscoverInstancesRequest direquest = new DiscoverInstancesRequest();
    direquest.setNamespaceName("my-apps");
    direquest.setServiceName("frontend");
    // Use a filter to retrieve the service based on environment and version
    Map<String, String> filtermap = new HashMap<String, String>();
    // Stage - key of the custom attribute, Dev - value of the custom attribute
    filtermap.put("Stage", "Dev");
    // Version - key of the custom attribute, 01 - value of the custom attribute
    filtermap.put("Version", "01");
    direquest.setQueryParameters(filtermap);
    System.out.println(client.discoverInstances(direquest));
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) HashMap(java.util.HashMap) AWSServiceDiscovery(com.amazonaws.services.servicediscovery.AWSServiceDiscovery) AmazonClientException(com.amazonaws.AmazonClientException) DiscoverInstancesRequest(com.amazonaws.services.servicediscovery.model.DiscoverInstancesRequest) ProfileCredentialsProvider(com.amazonaws.auth.profile.ProfileCredentialsProvider) AWSCredentials(com.amazonaws.auth.AWSCredentials) AmazonClientException(com.amazonaws.AmazonClientException)

Aggregations

AmazonClientException (com.amazonaws.AmazonClientException)4 AWSCredentials (com.amazonaws.auth.AWSCredentials)4 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)4 AWSServiceDiscovery (com.amazonaws.services.servicediscovery.AWSServiceDiscovery)4 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)3 DiscoverInstancesRequest (com.amazonaws.services.servicediscovery.model.DiscoverInstancesRequest)2 EnvironmentVariableCredentialsProvider (com.amazonaws.auth.EnvironmentVariableCredentialsProvider)1 CreateServiceRequest (com.amazonaws.services.servicediscovery.model.CreateServiceRequest)1 DiscoverInstancesResult (com.amazonaws.services.servicediscovery.model.DiscoverInstancesResult)1 ListInstancesRequest (com.amazonaws.services.servicediscovery.model.ListInstancesRequest)1 HashMap (java.util.HashMap)1