Reputation: 2217
I'm looking for a simple AWS example that shows how you can make an API call to my ASP.NET Web API service hosted in Beanstalk, get JSON and parse it AWS Android SDK. I found several but they are specific to IOT or Cognito and do not show parsing. My service is in Beanstalk so it doesn't really matter as it will be just an API call being made. I will look into Cognito once I see parsing in action. Examples I find seem to be tied to other services from AWS that I'm not interested in, like IOT or Lambda.
I don't even know if Amazon SDK offers parsing - that is actually what I'm trying to find out. I hope it does as I do not want to have to manually parse every object.
New to AWS and exploring the innumerable services AWS provides and trying to find out the minimum I need to create an app.
Upvotes: 0
Views: 464
Reputation: 3593
You can check one of the solution for calling API:
private AmazonCloudWatchClient client(final String awsAccessKey, final String awsSecretKey) {
final AmazonCloudWatchClient client = new AmazonCloudWatchClient(new BasicAWSCredentials(awsAccessKey, awsSecretKey));
client.setEndpoint("http://monitoring.eu-west-1.amazonaws.com");
return client;
}
private GetMetricStatisticsRequest request(final String instanceId, String metricName) {
final long twentyFourHrs = 1000 * 60 * 60 * 24;
final int oneHour = 60 * 60;
return new GetMetricStatisticsRequest().withStartTime(new Date(new Date().getTime() - twentyFourHrs)).withNamespace("AWS/EC2").withPeriod(oneHour)
.withDimensions(new Dimension().withName("InstanceId").withValue(instanceId)).withMetricName(metricName).withStatistics("Average", "Maximum")
.withEndTime(new Date());
}
private GetMetricStatisticsResult result(final AmazonCloudWatchClient client, final GetMetricStatisticsRequest awsRequest) {
return client.getMetricStatistics(awsRequest);
}
private void toStdOut(final GetMetricStatisticsResult result, final String instanceId) {
System.out.println(result); // outputs empty result: {Label:
// CPUUtilization,Datapoints: []}
System.out.println(result.getDatapoints().size() + "SIZE!!!");
for (final Datapoint dataPoint : result.getDatapoints()) {
System.out.println("!!!!");
System.out.printf("%s instance's average CPU utilization : %s%n", instanceId, dataPoint.getAverage());
System.out.printf("%s instance's max CPU utilization : %s%n", instanceId, dataPoint.getMaximum());
}
}
If you will be more precise, I can help you more.
Upvotes: 0