Example usage for com.amazonaws.util EC2MetadataUtils getAmiId

List of usage examples for com.amazonaws.util EC2MetadataUtils getAmiId

Introduction

In this page you can find the example usage for com.amazonaws.util EC2MetadataUtils getAmiId.

Prototype

public static String getAmiId() 

Source Link

Document

Get the AMI ID used to launch the instance.

Usage

From source file:com.boundlessgeo.suite.geoserver.cloudwatch.aws.MetricDatumEncoder.java

License:Open Source License

private void setUp() {
    try {// w w w .  ja  v  a  2s . com
        if (enablePerInstanceMetrics) {
            amiId = EC2MetadataUtils.getAmiId();
            logger.info("Detected AMI ID of {}", amiId);
            instanceType = EC2MetadataUtils.getInstanceType();
            logger.info("Detected Instance Type = {}", instanceType);
            if (StringUtils.isBlank(instanceId)) {
                instanceId = EC2MetadataUtils.getInstanceId();
                logger.info("Detected Instance Id of {}", instanceId);
            } else
                logger.info("Instance Id overridden with {}", instanceId);
        }
        setup = true;
    } catch (Exception ex) {
        logger.error("Unable to determine AMI ID or Instance type...are we on AWS?");
        logger.error(ex.getMessage());
        //only try this once....the strings can just be empty if it fails.
        //the sender will catch it anyways
        setup = true;
    }
}