fix public IP not working in EC2 autoscaling

This commit is contained in:
Xavier Léauté 2015-06-03 15:46:10 -07:00
parent 20fdb627d9
commit 4ebdfea76f
1 changed files with 33 additions and 24 deletions

View File

@ -108,31 +108,40 @@ public class EC2AutoScaler implements AutoScaler<EC2EnvironmentConfig>
} }
} }
final RunInstancesResult result = amazonEC2Client.runInstances( RunInstancesRequest request = new RunInstancesRequest(
new RunInstancesRequest( workerConfig.getAmiId(),
workerConfig.getAmiId(), workerConfig.getMinInstances(),
workerConfig.getMinInstances(), workerConfig.getMaxInstances()
workerConfig.getMaxInstances() )
.withInstanceType(workerConfig.getInstanceType())
.withPlacement(new Placement(envConfig.getAvailabilityZone()))
.withKeyName(workerConfig.getKeyName())
.withIamInstanceProfile(
workerConfig.getIamProfile() == null
? null
: workerConfig.getIamProfile().toIamInstanceProfileSpecification()
) )
.withInstanceType(workerConfig.getInstanceType()) .withUserData(userDataBase64);
.withSecurityGroupIds(workerConfig.getSecurityGroupIds())
.withPlacement(new Placement(envConfig.getAvailabilityZone())) // InstanceNetworkInterfaceSpecification.getAssociatePublicIpAddress may be
.withKeyName(workerConfig.getKeyName()) // true or false by default in EC2, depending on the subnet.
.withSubnetId(workerConfig.getSubnetId()) // Setting EC2NodeData.getAssociatePublicIpAddress explicitly will use that value instead,
.withIamInstanceProfile( // leaving it null uses the EC2 default.
workerConfig.getIamProfile() == null if (workerConfig.getAssociatePublicIpAddress() != null) {
? null request.withNetworkInterfaces(
: workerConfig.getIamProfile().toIamInstanceProfileSpecification() new InstanceNetworkInterfaceSpecification()
) .withAssociatePublicIpAddress(workerConfig.getAssociatePublicIpAddress())
.withNetworkInterfaces( .withSubnetId(workerConfig.getSubnetId())
workerConfig.getAssociatePublicIpAddress() == null .withGroups(workerConfig.getSecurityGroupIds())
? null .withDeviceIndex(0)
: new InstanceNetworkInterfaceSpecification().withAssociatePublicIpAddress( );
workerConfig.getAssociatePublicIpAddress() } else {
) request
) .withSecurityGroupIds(workerConfig.getSecurityGroupIds())
.withUserData(userDataBase64) .withSubnetId(workerConfig.getSubnetId());
); }
final RunInstancesResult result = amazonEC2Client.runInstances(request);
final List<String> instanceIds = Lists.transform( final List<String> instanceIds = Lists.transform(
result.getReservation().getInstances(), result.getReservation().getInstances(),