vendredi 6 février 2015

The parameter groupName cannot be used with the parameter subnet AWS SDK

I am trying to create a spot instance using AWS SDK, but I am facing a problem while using security group names and subnets. The error that I get while I try to give security groups and subnet id in the launch specification is:



The parameter groupName cannot be used with the parameter subnet


I have tried a number of resources online and have tried different ways to solve the situation, however I have been unable to resolve the problem. In some of the solutions I see that people suggest using setGroupID or withAllGroupNames function but neither of them works, the former is not even present in the AWS SDK, the only functions available are set/withGroupNames or set/withAllGroupNames. If anyone has a solution, I would be highly obliged if they can show me a work around for this problem.


Thanks.


Here is my code:



RequestSpotInstancesRequest requestRequest = new RequestSpotInstancesRequest();
// Request 1 x m3.medium instance with a bid price of $0.009.
requestRequest.setSpotPrice("0.009");
requestRequest.setInstanceCount(Integer.valueOf(1));
// Setup the specifications of the launch. This includes the
// instance type (e.g. m3.medium) and the latest Amazon Linux
// AMI id available. Note, you should always use the latest
// Amazon Linux AMI id or another of your choosing.
LaunchSpecification launchSpecification = new LaunchSpecification();
launchSpecification.setImageId("ami-4c4e0f24");
launchSpecification.setInstanceType("m3.medium");

CreateSecurityGroupRequest csgr = new CreateSecurityGroupRequest();

csgr.withGroupName("loadGeneratorS_G2").withDescription("Security group load generator");



CreateSecurityGroupResult createSecurityGroupResult =
ec2.createSecurityGroup(csgr);

IpPermission ipPermission = new IpPermission();
ipPermission.setIpProtocol("tcp");
ipPermission.setFromPort(80);
ipPermission.setToPort(80);

AuthorizeSecurityGroupIngressRequest authorizeSecurityGroupIngressRequest =
new AuthorizeSecurityGroupIngressRequest();

authorizeSecurityGroupIngressRequest.withGroupId(createSecurityGroupResult.getGroupId())
.withIpPermissions(ipPermission);

ec2.authorizeSecurityGroupIngress(authorizeSecurityGroupIngressRequest);

//Create Instance Request
RunInstancesRequest runInstancesRequest = new RunInstancesRequest();
//Add the security group to the request.

launchSpecification.setSubnetId(createSecurityGroupResult.getGroupId());
launchSpecification.withSubnetId("subnet-8071a1ab");


// Add the launch specifications to the request.
requestRequest.setLaunchSpecification(launchSpecification);

//Launch Instance
RequestSpotInstancesResult requestResult = ec2.requestSpotInstances(requestRequest);

Aucun commentaire:

Enregistrer un commentaire