×
☰ See All Chapters

AWS Java SDK program to reboot an EC2 instance

RebootInstance.java

package com.java4coding;

import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.PropertiesFileCredentialsProvider;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.ec2.AmazonEC2;
import com.amazonaws.services.ec2.AmazonEC2Client;
import com.amazonaws.services.ec2.model.RebootInstancesRequest;

public class RebootInstance {
   
public static void main(String[] args) {
       
AWSCredentialsProvider provider = new PropertiesFileCredentialsProvider(
               
"F:\\My_Programs\\AWS\\AWSEC2Example\\src\\main\\resources\\awscredentials.properties");

       
AmazonEC2 amazonEC2Client = AmazonEC2Client.builder()
               .withRegion(
Regions.US_WEST_2)
               .withCredentials(
provider)
               .build();
       
RebootInstancesRequest rebootInstancesRequest = new RebootInstancesRequest();
       
rebootInstancesRequest.withInstanceIds("instanceId");
       
amazonEC2Client.rebootInstances(rebootInstancesRequest);
   }
}

 

 

 


All Chapters
Author