本文整理汇总了Java中com.amazonaws.services.ec2.AmazonEC2.runInstances方法的典型用法代码示例。如果您正苦于以下问题:Java AmazonEC2.runInstances方法的具体用法?Java AmazonEC2.runInstances怎么用?Java AmazonEC2.runInstances使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.ec2.AmazonEC2
的用法示例。
在下文中一共展示了AmazonEC2.runInstances方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import com.amazonaws.services.ec2.AmazonEC2; //导入方法依赖的package包/类
@Override
public void execute(AmazonEC2 client, Pool pool, DelegateExecution execution) throws IOException {
final RunInstancesRequest request = createOnDemandInstancesRequest(pool, execution);
// TODO allow for more options (e.g. monitoring & termination protection etc.)
LOG.info(">> Sending RunInstances request: {}", request);
RunInstancesResult result = client.runInstances(request);
LOG.info("<< Got RunInstances result: {}", result);
// TODO tag instances: managed-by: Apache Provisionr, business-key: ID etc.
execution.setVariable(ProcessVariables.RESERVATION_ID,
result.getReservation().getReservationId());
execution.setVariable(ProcessVariables.INSTANCE_IDS,
collectInstanceIdsAsList(result.getReservation().getInstances()));
}
示例2: launchInstance
import com.amazonaws.services.ec2.AmazonEC2; //导入方法依赖的package包/类
/**
* @inheritDoc
*/
@Override
public String launchInstance( CreateInstanceOptions options,
Identity identity )
{
RunInstancesRequest request = new RunInstancesRequest();
if ( options.getInstanceProfileName() != null )
{
request.setIamInstanceProfile( new IamInstanceProfileSpecification().withName( options.getInstanceProfileName() ) );
}
request.setSubnetId( options.getWorkerOptions().getSubnetId() );
request.setSecurityGroupIds( options.getWorkerOptions().getSecurityGroupIds() );
if ( options.getUserData() != null )
{
request.setUserData( Base64.encodeBase64String( options.getUserData().getBytes() ) );
}
request.withMinCount( 1 ).withMaxCount( 1 ).withImageId( config.getAgentAmiId() ).withInstanceType( InstanceType.T1Micro );
request.setKeyName( options.getWorkerOptions().getKeyPairName() );
request.setClientToken( "launch-ec2-worker-"
+ contextProvider.getActivityExecutionContext().getWorkflowExecution().getWorkflowId() );
AmazonEC2 ec2 =
ActivityUtils.createClient( AmazonEC2Client.class, identity );
RunInstancesResult result = ec2.runInstances( request );
return result.getReservation().getInstances().get( 0 ).getInstanceId();
}
示例3: startInstance
import com.amazonaws.services.ec2.AmazonEC2; //导入方法依赖的package包/类
public static InstanceObject startInstance(AmazonEC2 ec2)
{
RunInstancesRequest runInstancesRequest = new RunInstancesRequest();
runInstancesRequest.withImageId("ami-f6ed6785")
.withMonitoring(true)
.withInstanceType("t2.micro")
.withMinCount(1)
.withMaxCount(1)
.withKeyName("CNV-lab-AWS")
.withSecurityGroups("CNV-ssh+http");
RunInstancesResult runInstancesResult = ec2.runInstances(runInstancesRequest);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {}
DescribeInstancesResult describeInstancesResult = ec2.describeInstances();
List<Reservation> reservations = describeInstancesResult.getReservations();
ArrayList<Instance> auxListOfInstances = new ArrayList<Instance>();
for (Reservation reservation : reservations) {
auxListOfInstances.addAll(reservation.getInstances());
}
InstanceObject instanceObject = null;
for (Instance instance : auxListOfInstances) {
if(instance.getInstanceId().equals(runInstancesResult.getReservation().getInstances().get(0).getInstanceId())) //id do load balancer, nao adicionamos este as instancias
instanceObject = new InstanceObject(instance);
}
//retornamos a instance criada
return instanceObject;
}
示例4: runInstances
import com.amazonaws.services.ec2.AmazonEC2; //导入方法依赖的package包/类
private RunInstancesResult runInstances(AmazonEC2 conn, String imageId, String instanceType, int count,
String subnetId, String securityGroup, String keyName) {
RunInstancesRequest runInstancesRequest = new RunInstancesRequest()
.withImageId(imageId)
.withInstanceType(instanceType)
.withMinCount(count)
.withMaxCount(count)
.withSubnetId(subnetId)
.withSecurityGroups(securityGroup)
.withKeyName(keyName);
return conn.runInstances(runInstancesRequest);
}
示例5: main
import com.amazonaws.services.ec2.AmazonEC2; //导入方法依赖的package包/类
public static void main(String[] args)
{
final String USAGE =
"To run this example, supply an instance name and AMI image id\n" +
"Ex: CreateInstance <instance-name> <ami-image-id>\n";
if (args.length != 2) {
System.out.println(USAGE);
System.exit(1);
}
String name = args[0];
String ami_id = args[1];
final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
RunInstancesRequest run_request = new RunInstancesRequest()
.withImageId(ami_id)
.withInstanceType(InstanceType.T1Micro)
.withMaxCount(1)
.withMinCount(1);
RunInstancesResult run_response = ec2.runInstances(run_request);
String instance_id = run_response.getReservation().getReservationId();
Tag tag = new Tag()
.withKey("Name")
.withValue(name);
CreateTagsRequest tag_request = new CreateTagsRequest()
.withTags(tag);
CreateTagsResult tag_response = ec2.createTags(tag_request);
System.out.printf(
"Successfully started EC2 instance %s based on AMI %s",
instance_id, ami_id);
}
示例6: createMachine
import com.amazonaws.services.ec2.AmazonEC2; //导入方法依赖的package包/类
@Override
public String createMachine( TargetHandlerParameters parameters ) throws TargetException {
this.logger.fine( "Creating a new machine on AWS." );
// For IaaS, we only expect root instance names to be passed
if( InstanceHelpers.countInstances( parameters.getScopedInstancePath()) > 1 )
throw new TargetException( "Only root instances can be passed in arguments." );
String rootInstanceName = InstanceHelpers.findRootInstancePath( parameters.getScopedInstancePath());
// Deal with the creation
String instanceId;
try {
AmazonEC2 ec2 = createEc2Client( parameters.getTargetProperties());
String userData = UserDataHelpers.writeUserDataAsString(
parameters.getMessagingProperties(),
parameters.getDomain(),
parameters.getApplicationName(),
rootInstanceName );
RunInstancesRequest runInstancesRequest = prepareEC2RequestNode( parameters.getTargetProperties(), userData );
RunInstancesResult runInstanceResult = ec2.runInstances( runInstancesRequest );
instanceId = runInstanceResult.getReservation().getInstances().get( 0 ).getInstanceId();
} catch( Exception e ) {
this.logger.severe( "An error occurred while creating a new machine on EC2. " + e.getMessage());
throw new TargetException( e );
}
return instanceId;
}
示例7: run
import com.amazonaws.services.ec2.AmazonEC2; //导入方法依赖的package包/类
public static void run(AmazonEC2 machines, String pathToScript, int count, String profileArn) throws IOException {
machines.runInstances(
new RunInstancesRequest()
.withImageId("ami-c7c0d6b3") // This used to be the official, Ireland running, 32 bit Amazon Machine Image. Or pick, for instance, [Ubuntu](http://cloud-images.ubuntu.com/locator/ec2/)
.withInstanceType(InstanceType.T1Micro) // Smallest possible, cheapest. Be warned: Cc28xlarge can set you back 3.75$ per call per machine per hour... [Pricing](http://aws.amazon.com/fr/ec2/#pricing)
.withMaxCount(count)
.withMinCount(count)
.withInstanceInitiatedShutdownBehavior(ShutdownBehavior.Terminate)
.withIamInstanceProfile(new IamInstanceProfileSpecification().withArn(profileArn))
.withUserData(printBase64Binary(FileUtils.readFileToString(new File(pathToScript), "UTF-8").getBytes("UTF-8")))
);
}
示例8: createSimpleInstance
import com.amazonaws.services.ec2.AmazonEC2; //导入方法依赖的package包/类
public static Instance createSimpleInstance(AmazonEC2 ec2Client) {
RunInstancesRequest runInstancesRequest = new RunInstancesRequest(EnvironmentSetupForTests.AMI_FOR_INSTANCE, 1, 1).
withInstanceType(InstanceType.T1Micro);
RunInstancesResult instancesResults = ec2Client.runInstances(runInstancesRequest);
List<Instance> instances = instancesResults.getReservation().getInstances();
return instances.get(0);
}
示例9: CreateServer
import com.amazonaws.services.ec2.AmazonEC2; //导入方法依赖的package包/类
public static String CreateServer(String keys, JSONObject endpointsAPI, String imageId, String typeId, String keypair)
{
String instanceId = null;
String accessKey = keys.split(";")[0];
String secretKey = keys.split(";")[1];
String regionEndpoint = (String) endpointsAPI.get("amazon-regionEndpoint");
try
{
// EC2 Client for given region and credentials
AmazonEC2 ec2 = new AmazonEC2Client(new BasicAWSCredentials(accessKey, secretKey));
ec2.setEndpoint(regionEndpoint);
RunInstancesRequest req = new RunInstancesRequest();
req.withInstanceType(typeId);
req.withImageId(imageId);
req.withMinCount(1).withMaxCount(1);
req.withSecurityGroups("securityGroup");
req.withKeyName(keypair);
// Execute run instance request and return ID of first (and only) instance
RunInstancesResult runInstances = ec2.runInstances(req);
instanceId = runInstances.getReservation().getInstances().get(0).getInstanceId();
}
catch (AmazonServiceException ase)
{
System.out.println("Caught an AmazonServiceException, which means your request made it " + "to AWS, but was rejected with an error response for some reason.");
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());
instanceId = "MSG_FAILED";
}
catch (AmazonClientException ace)
{
System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with AWS, " + "such as not being able to access the network.");
System.out.println("Error Message: " + ace.getMessage());
instanceId = "MSG_FAILED";
}
return instanceId;
}
示例10: runInstance
import com.amazonaws.services.ec2.AmazonEC2; //导入方法依赖的package包/类
private String runInstance(RunInstancesRequest request) {
AmazonEC2 ec2 = this.ec2Client.getClient();
RunInstancesResult runInstances = ec2.runInstances(request);
List<Instance> instances = runInstances.getReservation().getInstances();
return instances.get(0).getInstanceId();
}