diff --git a/pom.xml b/pom.xml index f0cb9f80389dc..7ff84270774e9 100644 --- a/pom.xml +++ b/pom.xml @@ -52,7 +52,7 @@ com.amazonaws aws-java-sdk - 1.3.10 + 1.3.11 compile diff --git a/src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java b/src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java index c6be4b3173357..c8641f8968d6f 100644 --- a/src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java +++ b/src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java @@ -21,7 +21,8 @@ import com.amazonaws.ClientConfiguration; import com.amazonaws.Protocol; -import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.auth.*; +import com.amazonaws.internal.StaticCredentialsProvider; import com.amazonaws.services.ec2.AmazonEC2; import com.amazonaws.services.ec2.AmazonEC2Client; import org.elasticsearch.ElasticSearchException; @@ -70,13 +71,6 @@ public synchronized AmazonEC2 client() { String account = componentSettings.get("access_key", settings.get("cloud.account")); String key = componentSettings.get("secret_key", settings.get("cloud.key")); - if (account == null) { - throw new ElasticSearchIllegalArgumentException("No aws access_key defined for ec2 discovery"); - } - if (key == null) { - throw new ElasticSearchIllegalArgumentException("No aws secret_key defined for ec2 discovery"); - } - String proxyHost = componentSettings.get("proxy_host"); if (proxyHost != null) { String portString = componentSettings.get("proxy_port", "80"); @@ -89,7 +83,21 @@ public synchronized AmazonEC2 client() { clientConfiguration.withProxyHost(proxyHost).setProxyPort(proxyPort); } - this.client = new AmazonEC2Client(new BasicAWSCredentials(account, key), clientConfiguration); + AWSCredentialsProvider credentials; + + if (account == null && key == null) { + credentials = new AWSCredentialsProviderChain( + new EnvironmentVariableCredentialsProvider(), + new SystemPropertiesCredentialsProvider(), + new InstanceProfileCredentialsProvider() + ); + } else { + credentials = new AWSCredentialsProviderChain( + new StaticCredentialsProvider(new BasicAWSCredentials(account, key)) + ); + } + + this.client = new AmazonEC2Client(credentials, clientConfiguration); if (componentSettings.get("ec2.endpoint") != null) { client.setEndpoint(componentSettings.get("ec2.endpoint")); diff --git a/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java b/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java index 52f343e850299..fcf89624140ff 100644 --- a/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java +++ b/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java @@ -21,7 +21,8 @@ import com.amazonaws.ClientConfiguration; import com.amazonaws.Protocol; -import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.auth.*; +import com.amazonaws.internal.StaticCredentialsProvider; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3Client; import org.elasticsearch.ElasticSearchException; @@ -62,13 +63,6 @@ public synchronized AmazonS3 client() { String account = componentSettings.get("access_key", settings.get("cloud.account")); String key = componentSettings.get("secret_key", settings.get("cloud.key")); - if (account == null) { - throw new ElasticSearchIllegalArgumentException("No s3 access_key defined for s3 gateway"); - } - if (key == null) { - throw new ElasticSearchIllegalArgumentException("No s3 secret_key defined for s3 gateway"); - } - String proxyHost = componentSettings.get("proxy_host"); if (proxyHost != null) { String portString = componentSettings.get("proxy_port", "80"); @@ -81,7 +75,20 @@ public synchronized AmazonS3 client() { clientConfiguration.withProxyHost(proxyHost).setProxyPort(proxyPort); } - this.client = new AmazonS3Client(new BasicAWSCredentials(account, key), clientConfiguration); + AWSCredentialsProvider credentials; + + if (account == null && key == null) { + credentials = new AWSCredentialsProviderChain( + new EnvironmentVariableCredentialsProvider(), + new SystemPropertiesCredentialsProvider(), + new InstanceProfileCredentialsProvider() + ); + } else { + credentials = new AWSCredentialsProviderChain( + new StaticCredentialsProvider(new BasicAWSCredentials(account, key)) + ); + } + this.client = new AmazonS3Client(credentials, clientConfiguration); if (componentSettings.get("s3.endpoint") != null) { client.setEndpoint(componentSettings.get("s3.endpoint"));