2017-05-27 3 views
0

Ich versuche, eine neue AWS EC2-Instanz mithilfe des AWS Java SDK zu erstellen, aber "Value() für Parameter groupId ist ungültig. Der Wert darf nicht leer sein" . Hier ist mein Code:So erstellen Sie eine neue AWS-Instanz mit AWS Java SDK

AWSCredentials credentials = null; 
try { 
    credentials = new ProfileCredentialsProvider().getCredentials(); 
} catch (Exception e) { 
    throw new AmazonClientException(
     "Cannot load the credentials from the credential profiles file. " + 
     "Please make sure that your credentials file is at the correct " + 
     "location (~/.aws/credentials), and is in valid format.", 
     e); 
} 

ec2 = AmazonEC2ClientBuilder.standard() 
    .withCredentials(new AWSStaticCredentialsProvider(credentials)) 
    .withRegion(Regions.US_WEST_2) 
    .build(); 

}

RunInstancesRequest runInstancesRequest = new RunInstancesRequest(); 
String ami_id = "ami-efd0428f";  //ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20170414 
Collection<String> securityGroups = new ArrayList<>(); 
securityGroups.add("launch-wizard-1"); 
securityGroups.add("sg-9405c2f3"); 
runInstancesRequest.withImageId(ami_id) 
    .withInstanceType("t2.medium") 
    .withMinCount(1) 
    .withMaxCount(1) 
    .withKeyName("MyKeyName") 
    .withSecurityGroups(securityGroups); 

RunInstancesResult run_response = ec2.runInstances(runInstancesRequest); // fails here! 

String instance_id = run_response.getReservation().getReservationId(); 

Tag tag = new Tag() 
    .withKey("Name") 
    .withValue(tfCompanyName.getText()); 
Collection<Tag> tags = new ArrayList<>(); 
tags.add(tag); 

CreateTagsRequest tag_request = new CreateTagsRequest(); 
tag_request.setTags(tags); 

CreateTagsResult tag_response = ec2.createTags(tag_request); 

String s = String.format("Successfully started EC2 instance %s based on AMI %s",instance_id, ami_id); 
System.out.println(s); 

Irgendwelche Vorschläge?

Antwort

0

Möglicherweise müssen Sie auch eine VPC-Details hinzufügen.

PrivateIpAddresses, Überwachung sind unter anderen erforderlichen Feldern.

Ich würde Ihnen empfehlen, zu versuchen, EC2-Instance manuell mit AWS Console zu erstellen und zu sehen, welche Parameter gefragt sind?

+0

Die VPC-Sache ist wahrscheinlich das Problem, da ich eine von denen habe (was auch immer es ist). Wie schließe ich es an? Ich sehe keine .withVPC Optionen. – user3217883

+0

Ich habe einen mit der AWS-Konsole erstellt. Das einzige Erforderliche war ein AMI, Type und KeyPair – user3217883

Verwandte Themen