Skip to content

Instantly share code, notes, and snippets.

@morizotter
Created July 8, 2014 05:46
Show Gist options
  • Save morizotter/1ec443798f267609d477 to your computer and use it in GitHub Desktop.
Save morizotter/1ec443798f267609d477 to your computer and use it in GitHub Desktop.
iOSから直接AWSのCloudWatch APIを叩いて利用料金データを取得してみたよ ref: http://qiita.com/morizotter/items/70f83f1e75ebc70be94c
#import "ACSViewController.h"
#import <AWSCloudWatch/AWSCloudWatch.h>
@interface ACSViewController ()
@end
@implementation ACSViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self getData];
}
- (void)getData
{
AmazonCloudWatchClient *client =
[[AmazonCloudWatchClient alloc] initWithAccessKey:@"YOUR_ACCESS_KEY_ID"
withSecretKey:@"YOUR_SECRET_ACCESS_KEY"];
CloudWatchDimension *dimension = [[CloudWatchDimension alloc] init];
dimension.name = @"Currency";
dimension.value = @"USD";
NSDate *startDate = [NSDate dateWithTimeInterval:-60 * 60 * 24 sinceDate:[NSDate date]];
NSDate *endDate = [NSDate date];
CloudWatchGetMetricStatisticsRequest *request = [[CloudWatchGetMetricStatisticsRequest alloc] init];
request.metricName = @"EstimatedCharges";
request.namespace = @"AWS/Billing";
request.statistics = @[@"Sum", @"Average", @"Minimum", @"Maximum"].mutableCopy;
request.startTime = startDate;
request.endTime = endDate;
request.period = @60;
[request addDimension:dimension];
CloudWatchGetMetricStatisticsResponse *response = [client getMetricStatistics:request];
if (response.error) {
NSLog(@"error: %@", response.error);
return;
}
NSLog(@"label: %@\ndata points: %@", response.label, response.datapoints);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment