1

我曾尝试使用 AttachVolumeRequest 但作为响应我收到以下错误

 Caught Exception: The request must contain the parameter volume
 Reponse Status Code: 400
 Error Code: MissingParameter

这是我的代码,在此代码中,ec2 是我的 amazonclient 对象,到目前为止它工作正常

AttachVolumeRequest attachRequest=new AttachVolumeRequest()
    .withInstanceId("my instance id");
attachRequest.setRequestCredentials(credentials);

EbsBlockDevice ebs=new EbsBlockDevice();
ebs.setVolumeSize(2);

//attachRequest.withVolumeId(ebs.getSnapshotId());

AttachVolumeResult result=ec2.attachVolume(attachRequest);

非常感谢任何帮助。提前致谢

4

1 回答 1

3

原因

AWS SDK for Java中的EbsBlockDevice类用于不同的目的,因此方法getSnapshotId()仅返回将创建卷的快照的 ID,即不是卷 ID,因此是相应的例外。

解决方案

您很可能想改用CreateVolumeRequest类,例如(从我的脑海中):

CreateVolumeRequest createVolumeRequest = new CreateVolumeRequest()
    .withAvailabilityZone("my instance's AZ") // The AZ in which to create the volume.
    .withSize(2); // The size of the volume, in gigabytes.

CreateVolumeResult createVolumeResult = ec2.createVolume(createVolumeRequest);

AttachVolumeRequest attachRequest = new AttachVolumeRequest()
    .withInstanceId("my instance id");
    .withVolumeId(createVolumeResult.getVolume().getVolumeId());

AttachVolumeResult attachResult = ec2.attachVolume(attachRequest);
于 2013-04-12T16:16:57.663 回答