2014-07-09 165 views
1

我想使用新的「gp2」卷類型作爲我的Windows實例的啓動卷,帶有來自Amazon的開箱即用Windows AMI(例如ami-527b823a)和AWS SDK for .NET( v2.1.7 - 截至2014年7月9日最新)。我如何配置我的運行實例請求?如何爲我的Windows EC2實例配置gp2啓動卷?

基於the post on the AWS blog,我嘗試設置一個BlockDeviceMapping:

new RunInstancesRequest { 
    ... 
    BlockDeviceMappings = { 
     BlockDeviceMapping { 
      DeviceName = "sda1", 
      Ebs = new EbsBlockDevice { VolumeType = VolumeType.Gp2 } 
     }, 
     new BlockDeviceMapping { 
      DeviceName = "xvdf", 
      Ebs = new EbsBlockDevice { 
       SnapshotId = SNAPSHOT_ID 
       DeleteOnTermination = true, 
       VolumeType = VolumeType.Gp2 
      } 
     } 
     ... 
    } 
} 

但這並沒有工作,我得到了一個令人吃驚的例外:

Amazon.EC2.AmazonEC2Exception: The device 'sda1' is used in more than one 
block-device mapping ---> System.Net.WebException: The remote server 
returned an error: (400) Bad Request. 
    at System.Net.HttpWebRequest.GetResponse() 
    ... 

是否可以設置啓動(根)我的Windows實例的音量到GP2?或者我需要等待SDK的更新版本?

+0

只是爲了進行仔細的檢查,你確定你'只爲根卷創建1 BlockDeviceMapping? –

+0

@HyperAnthony是的,我很確定。在使用「標準」EBS卷(我正在嘗試更改)的生產代碼中,我甚至沒有在RunInstancesRequest中指定根設備,只有第二個「xvdf」設備。 –

+0

您可以使用已經配置了GP2卷的2012R2 Windows AMI之一嗎?您可以使用以下命令(假設您已安裝適用於Windows Powershell的AWS Tools)獲取可用AMI的列表 - Get-EC2ImageByName - 名稱Windows_Server-2012-R2_RTM-English-64Bit-GP2 * –

回答

2

使用下面的代碼和AWS SDK用於.NET的2.1.7版本,我能夠與GP2 EBS根捲成功啓動:

BlockDeviceMapping mapping = new BlockDeviceMapping 
{ 
    DeviceName = "/dev/sda1", 
    Ebs = new EbsBlockDevice 
    { 
     VolumeType = VolumeType.Gp2, 
     VolumeSize = 30 
    } 
}; 
var request = new RunInstancesRequest 
{ 
    BlockDeviceMappings = { mapping }, 
    ImageId = "ami-527b823a", 
    InstanceType = InstanceType.M1Small, 
    MinCount = 1, 
    MaxCount =1 
}; 
var ec2Client = new AmazonEC2Client(RegionEndpoint.USEast1); 
ec2Client.RunInstances(request); 
+0

這也適用於我。有趣的是,DeviceName似乎是關鍵。 「sda1」會拋出,但「/ dev/sda1」通過。非常感謝! –