简体   繁体   English

使用ebs音量附加ec2

[英]Attaching ec2 with ebs volume

Here is my code for attachment of EC2 with EBS volume. 这是我的EC2与EBS卷附件的代码。

 private static AttachVolumeResult attachEBSVolume(String volumeId, String instanceId, String device){
     AttachVolumeRequest attachVolReq = new AttachVolumeRequest(volumeId, instanceId, device);
     return ec2.attachVolume(attachVolReq);
 }

Its works fine for the first time but when I run it again It gives the following exception. 它第一次工作正常,但是当我再次运行它时会出现以下异常。 Kindly tell me how can solve it and please also tell me what is the deviceName (3rd parameter) parameter in the parameter and what can be its possible values. 请告诉我如何解决它,并请告诉我参数中的deviceName(第三个参数)参数是什么,它可能是什么值。 Thanks 谢谢

This is function call shown below 
attachEBSVolume(createRes.getVolume().getVolumeId(), "InstanceIDhere", "xvdg");

Below is the Exception Arise :: 以下是Exception Arise ::

AWS Error Code: InvalidParameterValue, AWS Error Message: Invalid value 'xvdg' for unixDevice. Attachment point xvdg is already in use.

You are trying to attach different volumes to the same "xvdg" device. 您正尝试将不同的卷附加到同一“xvdg”设备。

You should use different devices too - xvdh, xvdi, ... xvdp. 您也应该使用不同的设备 - xvdh,xvdi,... xvdp。
Then inside of the instance you will see them as /dev/xvdg, /dev/xvdh, etc. 然后在实例内部,您将看到它们为/ dev / xvdg,/ dev / xvdh等。

You can attach only one EBS volume with one EC2 device. 您只能使用一个EC2设备连接一个EBS卷。 There are multiple devices available for example xvdg, xvdh, , /dev/sdf. 有多个设备可用,例如xvdg,xvdh,/ dev / sdf。 In the code what you are doing is that You are trying to attach a different EBS volume to same device , which is not allowed by AWS. 在代码中,您正在尝试将不同的EBS卷附加到同一设备,这是AWS不允许的。 so You can attach only one EBS volume with one device. 所以您只能在一台设备上附加一个EBS卷。

You can save the ID of EBS volume using this function 您可以使用此功能保存EBS卷的ID

CreateVolumeResult createRes = makeEBSVolume(volSize, availabilityZone, "taghere");
 createRes.getVolume().getVolumeId()     // to save the volume ID

After saving this ID you can attach this ID with your EC2 (instance ID) every time you need. 保存此ID后,您可以在每次需要时将此ID附加到EC2(实例ID)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM