Example usage for com.amazonaws.util EC2MetadataUtils getData

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

Introduction

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

Prototype

public static String getData(String path, int tries) 

Source Link

Usage

From source file:org.springframework.cloud.aws.context.annotation.OnAwsCloudEnvironmentCondition.java

License:Apache License

@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
    if (isCloudEnvironment == null) {
        try {/*from   w ww. j av a2  s.  c om*/
            isCloudEnvironment = EC2MetadataUtils.getData(EC2_METADATA_ROOT + "/instance-id", 1) != null;
        } catch (AmazonClientException e) {
            isCloudEnvironment = false;
        }
    }

    return isCloudEnvironment;
}

From source file:org.springframework.cloud.aws.context.support.env.AwsCloudEnvironmentCheckUtils.java

License:Apache License

public static boolean isRunningOnCloudEnvironment() {
    if (isCloudEnvironment == null) {
        try {/*from   ww  w. j a  v a 2  s  .com*/
            isCloudEnvironment = EC2MetadataUtils.getData(EC2_METADATA_ROOT + "/instance-id", 1) != null;
        } catch (AmazonClientException e) {
            isCloudEnvironment = false;
        }
    }
    return isCloudEnvironment;
}