com.amazonaws.services.ec2.model.RebootInstancesRequest Java Examples
The following examples show how to use
com.amazonaws.services.ec2.model.RebootInstancesRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RebootInstance.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
public static void main(String[] args) { final String USAGE = "To run this example, supply an instance id\n" + "Ex: RebootInstance <instance_id>\n"; if (args.length != 1) { System.out.println(USAGE); System.exit(1); } String instance_id = args[0]; final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient(); RebootInstancesRequest request = new RebootInstancesRequest() .withInstanceIds(instance_id); RebootInstancesResult response = ec2.rebootInstances(request); System.out.printf( "Successfully rebooted instance %s", instance_id); }
Example #2
Source File: AwsInstanceConnector.java From cloudbreak with Apache License 2.0 | 5 votes |
private void doReboot(List<CloudInstance> affectedVMs, AmazonEC2Client amazonEC2Client, List<CloudInstance> instances) { for (CloudInstance instance: instances) { try { amazonEC2Client.rebootInstances(new RebootInstancesRequest().withInstanceIds(List.of(instance.getInstanceId()))); affectedVMs.add(instance); } catch (AmazonEC2Exception e) { LOGGER.warn(String.format("Unable to reboot instance %s", instance), e); } } }
Example #3
Source File: InstanceImpl.java From aws-sdk-java-resources with Apache License 2.0 | 4 votes |
@Override public void reboot(RebootInstancesRequest request) { reboot(request, null); }
Example #4
Source File: InstanceImpl.java From aws-sdk-java-resources with Apache License 2.0 | 4 votes |
@Override public void reboot(RebootInstancesRequest request, ResultCapture<Void> extractor) { resource.performAction("Reboot", request, extractor); }
Example #5
Source File: InstanceImpl.java From aws-sdk-java-resources with Apache License 2.0 | 4 votes |
@Override public void reboot(ResultCapture<Void> extractor) { RebootInstancesRequest request = new RebootInstancesRequest(); reboot(request, extractor); }
Example #6
Source File: EC2Application.java From tutorials with MIT License | 4 votes |
public static void main(String[] args) { // Set up the client AmazonEC2 ec2Client = AmazonEC2ClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(credentials)) .withRegion(Regions.US_EAST_1) .build(); // Create a security group CreateSecurityGroupRequest createSecurityGroupRequest = new CreateSecurityGroupRequest().withGroupName("BaeldungSecurityGroup") .withDescription("Baeldung Security Group"); ec2Client.createSecurityGroup(createSecurityGroupRequest); // Allow HTTP and SSH traffic IpRange ipRange1 = new IpRange().withCidrIp("0.0.0.0/0"); IpPermission ipPermission1 = new IpPermission().withIpv4Ranges(Arrays.asList(new IpRange[] { ipRange1 })) .withIpProtocol("tcp") .withFromPort(80) .withToPort(80); IpPermission ipPermission2 = new IpPermission().withIpv4Ranges(Arrays.asList(new IpRange[] { ipRange1 })) .withIpProtocol("tcp") .withFromPort(22) .withToPort(22); AuthorizeSecurityGroupIngressRequest authorizeSecurityGroupIngressRequest = new AuthorizeSecurityGroupIngressRequest() .withGroupName("BaeldungSecurityGroup") .withIpPermissions(ipPermission1, ipPermission2); ec2Client.authorizeSecurityGroupIngress(authorizeSecurityGroupIngressRequest); // Create KeyPair CreateKeyPairRequest createKeyPairRequest = new CreateKeyPairRequest() .withKeyName("baeldung-key-pair"); CreateKeyPairResult createKeyPairResult = ec2Client.createKeyPair(createKeyPairRequest); String privateKey = createKeyPairResult .getKeyPair() .getKeyMaterial(); // make sure you keep it, the private key, Amazon doesn't store the private key // See what key-pairs you've got DescribeKeyPairsRequest describeKeyPairsRequest = new DescribeKeyPairsRequest(); DescribeKeyPairsResult describeKeyPairsResult = ec2Client.describeKeyPairs(describeKeyPairsRequest); // Launch an Amazon Instance RunInstancesRequest runInstancesRequest = new RunInstancesRequest().withImageId("ami-97785bed") // https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html | https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/usingsharedamis-finding.html .withInstanceType("t2.micro") // https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html .withMinCount(1) .withMaxCount(1) .withKeyName("baeldung-key-pair") // optional - if not present, can't connect to instance .withSecurityGroups("BaeldungSecurityGroup"); String yourInstanceId = ec2Client.runInstances(runInstancesRequest).getReservation().getInstances().get(0).getInstanceId(); // Start an Instance StartInstancesRequest startInstancesRequest = new StartInstancesRequest() .withInstanceIds(yourInstanceId); ec2Client.startInstances(startInstancesRequest); // Monitor Instances MonitorInstancesRequest monitorInstancesRequest = new MonitorInstancesRequest() .withInstanceIds(yourInstanceId); ec2Client.monitorInstances(monitorInstancesRequest); UnmonitorInstancesRequest unmonitorInstancesRequest = new UnmonitorInstancesRequest() .withInstanceIds(yourInstanceId); ec2Client.unmonitorInstances(unmonitorInstancesRequest); // Reboot an Instance RebootInstancesRequest rebootInstancesRequest = new RebootInstancesRequest() .withInstanceIds(yourInstanceId); ec2Client.rebootInstances(rebootInstancesRequest); // Stop an Instance StopInstancesRequest stopInstancesRequest = new StopInstancesRequest() .withInstanceIds(yourInstanceId); ec2Client.stopInstances(stopInstancesRequest) .getStoppingInstances() .get(0) .getPreviousState() .getName(); // Describe an Instance DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest(); DescribeInstancesResult response = ec2Client.describeInstances(describeInstancesRequest); System.out.println(response.getReservations() .get(0) .getInstances() .get(0) .getKernelId()); }
Example #7
Source File: Instance.java From aws-sdk-java-resources with Apache License 2.0 | 2 votes |
/** * Performs the <code>Reboot</code> action. * * <p> * The following request parameters will be populated from the data of this * <code>Instance</code> resource, and any conflicting parameter value set * in the request will be overridden: * <ul> * <li> * <b><code>InstanceIds.0</code></b> * - mapped from the <code>Id</code> identifier. * </li> * </ul> * * <p> * * @see RebootInstancesRequest */ void reboot(RebootInstancesRequest request);
Example #8
Source File: Instance.java From aws-sdk-java-resources with Apache License 2.0 | 2 votes |
/** * Performs the <code>Reboot</code> action and use a ResultCapture to * retrieve the low-level client response. * * <p> * The following request parameters will be populated from the data of this * <code>Instance</code> resource, and any conflicting parameter value set * in the request will be overridden: * <ul> * <li> * <b><code>InstanceIds.0</code></b> * - mapped from the <code>Id</code> identifier. * </li> * </ul> * * <p> * * @see RebootInstancesRequest */ void reboot(RebootInstancesRequest request, ResultCapture<Void> extractor);