Created
July 8, 2014 05:46
-
-
Save morizotter/1ec443798f267609d477 to your computer and use it in GitHub Desktop.
iOSから直接AWSのCloudWatch APIを叩いて利用料金データを取得してみたよ ref: http://qiita.com/morizotter/items/70f83f1e75ebc70be94c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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