Example usage for com.amazonaws.services.ec2 AmazonEC2Client getConsoleScreenshot

List of usage examples for com.amazonaws.services.ec2 AmazonEC2Client getConsoleScreenshot

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2 AmazonEC2Client getConsoleScreenshot.

Prototype

@Override
public GetConsoleScreenshotResult getConsoleScreenshot(GetConsoleScreenshotRequest request) 

Source Link

Document

Retrieve a JPG-format screenshot of a running instance to help with troubleshooting.

Usage

From source file:ec2watch.EC2Watch.java

License:Open Source License

public void run() {

    ImageViewer viewer = null;//  w  w  w .  j a  v a 2s. c  o  m
    AmazonEC2Client ec2Client = new AmazonEC2Client(clientConfiguration);

    if (region != null) {
        ec2Client.setRegion(Region.getRegion(Regions.fromName(region)));
    }

    while (true) {
        try {
            GetConsoleScreenshotResult result = ec2Client.getConsoleScreenshot(
                    new GetConsoleScreenshotRequest().withInstanceId(instanceId).withWakeUp(Boolean.TRUE));
            byte[] imageData = Base64.getDecoder().decode(result.getImageData());

            if (viewer == null) {
                viewer = new ImageViewer(instanceId, imageData);
            } else {
                viewer.setImageData(imageData);
                System.out.print(".");
            }

            Thread.sleep(interval * 1000);
        } catch (Exception e) {
            // Ignore it
            System.out.print("x");
        }

    }
}