我是AWS(亚马逊网络服务)和AWS sdk(JAVA)的新手。最初我试图找到如何在亚马逊中使用aws sdk创建VM但是找不到任何方法。
我发现使用EC2 Imageimport
的anther解决方案可以在AWS中使用您的本地磁盘创建VM,所以我正在尝试为它实现流程但是因为内部错误而失败
错误消息:发生内部错误(服务:AmazonEC2; 状态代码:500;错误代码:InternalError;请求ID: c3bab0f1-d70a-4c72-ba91-21004045088a)HTTP状态码:500 AWS错误 代码:InternalError错误类型:未知请求ID:
c3bab0f1-D70A-4c72-ba91-21004045088a
任何有AWS家庭的人都请帮帮我,如果有人知道在AWS中创建VM的方式,请在桶中上传磁盘,请分享。 以下是我的尝试。
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.regions.ServiceAbbreviations;
import com.amazonaws.services.ec2.AmazonEC2;
import com.amazonaws.services.ec2.AmazonEC2AsyncClient;
import com.amazonaws.services.ec2.model.ImageDiskContainer;
import com.amazonaws.services.ec2.model.ImportImageRequest;
import com.amazonaws.services.ec2.model.UserBucket;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.Bucket;
public class SSBucketFinder {
static AmazonS3 s3;
static AmazonEC2 ec2;
static AWSCredentials credentials = null;
private static void init() throws Exception {
credentials = new BasicAWSCredentials("#################",
"###############################");
s3 = new AmazonS3Client(credentials);
ec2 = new AmazonEC2AsyncClient(credentials);
}
public static void main(String[] args) throws Exception {
System.out.println("List of buckets:");
init();
try {
List<Bucket> buckets = s3.listBuckets();
for (Bucket bucket : buckets) {
System.out.println(bucket.getName());
}
} catch (AmazonServiceException ase) {
System.out.println("Error Message: " + ase.getMessage());
System.out.println("HTTP Status Code: " + ase.getStatusCode());
System.out.println("AWS Error Code: " + ase.getErrorCode());
System.out.println("Error Type: " + ase.getErrorType());
System.out.println("Request ID: " + ase.getRequestId());
} catch (AmazonClientException ace) {
System.out.println("Error Message: " + ace.getMessage());
}
UserBucket ub = new UserBucket();
ub.setS3Bucket("surebkt1");
ImportImageRequest iir = new ImportImageRequest();
Collection<ImageDiskContainer> diskContainers = new ArrayList<ImageDiskContainer>();
ImageDiskContainer idc = new ImageDiskContainer();
idc.setDeviceName("C:\\ubuntuminimal\\87EA3BAC-A8C0-4F76-ACA8-FE440C5C7B85_1.vhd");
idc.setFormat("vhd");
idc.setUserBucket(ub);
diskContainers.add(idc);
iir.setDiskContainers(diskContainers);
iir.setArchitecture("x86_64");
iir.setDescription("Import Task");
iir.setHypervisor("xen");
iir.setRequestCredentials(credentials);
iir.setPlatform("linux");
try {
System.out.println("EC2 Import image");
ec2.importImage(iir);
} catch (AmazonServiceException ase) {
System.out.println("Error Message: " + ase.getMessage());
System.out.println("HTTP Status Code: " + ase.getStatusCode());
System.out.println("AWS Error Code: " + ase.getErrorCode());
System.out.println("Error Type: " + ase.getErrorType());
System.out.println("Request ID: " + ase.getRequestId());
}
}
}