7
我試圖用CloudWatch的AWS - 如何更改cloudwatchclient配置服務版本AWSSDK爲.NET
我執行的代碼,當面對這個錯誤得到一個特定的Amazon EC2實例的CPU百分比(見下文)
服務的請求的版本(2010-08-01)AmazonEC2不存在」
在AmazonCloudWatchClient我不能改變ServiceVersion因爲它有Read Only property
的默認設置是2010-08-01
我需要的ServiceVersion更改爲2014-10-01
請在下面找到
配置和文本中的配置在這裏
var client = new AmazonCloudWatchClient(clientkey,secretkey,new AmazonCloudWatchConfig{ServiceURL="url"})
var dimension = new Dimension
{
Name = "instanceName",
Value = "instanceID"
};
var request = new GetMetricStatisticsRequest
{
Dimensions = new List<Dimension>() { dimension },
EndTime = DateTime.Today,
MetricName = "CPUUtilization",
Namespace = "AWS/EC2",
// Get statistics by day.
Period = (int)TimeSpan.FromDays(1).TotalSeconds,
// Get statistics for the past month.
StartTime = DateTime.Today.Subtract(TimeSpan.FromDays(30)),
Statistics = new List<string>() { "Minimum" },
Unit = StandardUnit.Percent
};
var response = client.GetMetricStatistics(request);
if (response.Datapoints.Count > 0)
{
foreach (var point in response.Datapoints)
{
Console.WriteLine(point.Timestamp.ToShortDateString() +
" " + point.Minimum + "%");
}
}
覆蓋不會發生在配置服務版本上。同樣的錯誤 – arun
是的,因爲在覆蓋沒有設置方法,但奇怪,使用正確的名稱參數與正確的關聯值應該工作 –
創建部分類和配置版本AmazonCloudWatchConfig Config = new AmazonCloudWatchConfig(); Config.RegionEndpoint = RegionEndpoint.USEast1; var client = new AmazonCloudWatchClient(「xxxxx」,「xxxx」,Config);這也沒有工作得到錯誤「不能轉換亞馬遜。cloudwatch.amazoncloudwatchconfig到amazon.regionendpoint」 – arun