diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java index d4812aa9d1f..1abe6e29f48 100644 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java +++ b/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java @@ -70,8 +70,31 @@ public class AwsEc2Service extends AbstractLifecycleComponent { this.client = new AmazonEC2Client(new BasicAWSCredentials(account, key), clientConfiguration); - if (componentSettings.get("endpoint") != null) { - client.setEndpoint(componentSettings.get("endpoint")); + if (componentSettings.get("ec2.endpoint") != null) { + client.setEndpoint(componentSettings.get("ec2.endpoint")); + } else if (componentSettings.get("region") != null) { + String endpoint; + String region = componentSettings.get("region"); + if ("us-east".equals(region.toLowerCase())) { + endpoint = "ec2.us-east-1.amazonaws.com"; + } else if ("us-east-1".equals(region.toLowerCase())) { + endpoint = "ec2.us-east-1.amazonaws.com"; + } else if ("us-west".equals(region.toLowerCase())) { + endpoint = "ec2.us-west-1.amazonaws.com"; + } else if ("us-west-1".equals(region.toLowerCase())) { + endpoint = "ec2.us-west-1.amazonaws.com"; + } else if ("ap-southeast".equals(region.toLowerCase())) { + endpoint = "ec2.ap-southeast-1.amazonaws.com"; + } else if ("ap-southeast-1".equals(region.toLowerCase())) { + endpoint = "ec2.ap-southeast-1.amazonaws.com"; + } else if ("eu-west".equals(region.toLowerCase())) { + endpoint = "ec2.eu-west-1.amazonaws.com"; + } else if ("eu-west-1".equals(region.toLowerCase())) { + endpoint = "ec2.eu-west-1.amazonaws.com"; + } else { + throw new ElasticSearchIllegalArgumentException("No automatic endpoint could be derived from region [" + region + "]"); + } + client.setEndpoint(endpoint); } return this.client; diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java index e3c563f051e..1eedc92e0a9 100644 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java +++ b/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java @@ -70,8 +70,31 @@ public class AwsS3Service extends AbstractLifecycleComponent { this.client = new AmazonS3Client(new BasicAWSCredentials(account, key), clientConfiguration); - if (componentSettings.get("endpoint") != null) { - client.setEndpoint(componentSettings.get("endpoint")); + if (componentSettings.get("s3.endpoint") != null) { + client.setEndpoint(componentSettings.get("s3.endpoint")); + } else if (componentSettings.get("region") != null) { + String endpoint; + String region = componentSettings.get("region"); + if ("us-east".equals(region.toLowerCase())) { + endpoint = "s3.amazonaws.com"; + } else if ("us-east-1".equals(region.toLowerCase())) { + endpoint = "s3.amazonaws.com"; + } else if ("us-west".equals(region.toLowerCase())) { + endpoint = "s3-us-west-1.amazonaws.com"; + } else if ("us-west-1".equals(region.toLowerCase())) { + endpoint = "s3-us-west-1.amazonaws.com"; + } else if ("ap-southeast".equals(region.toLowerCase())) { + endpoint = "s3-ap-southeast-1.amazonaws.com"; + } else if ("ap-southeast-1".equals(region.toLowerCase())) { + endpoint = "s3-ap-southeast-1.amazonaws.com"; + } else if ("eu-west".equals(region.toLowerCase())) { + endpoint = null; // no specific endpoint for EU (still can be used for region) + } else if ("eu-west-1".equals(region.toLowerCase())) { + endpoint = null; // no specific endpoint for EU (still can be used for region) + } else { + throw new ElasticSearchIllegalArgumentException("No automatic endpoint could be derived from region [" + region + "]"); + } + client.setEndpoint(endpoint); } return this.client; diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/AbstarctS3BlobContainer.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/AbstractS3BlobContainer.java similarity index 97% rename from plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/AbstarctS3BlobContainer.java rename to plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/AbstractS3BlobContainer.java index 8f894c36de8..f424433a9a0 100644 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/AbstarctS3BlobContainer.java +++ b/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/AbstractS3BlobContainer.java @@ -35,13 +35,13 @@ import java.io.InputStream; /** * @author kimchy (shay.banon) */ -public class AbstarctS3BlobContainer extends AbstractBlobContainer { +public class AbstractS3BlobContainer extends AbstractBlobContainer { protected final S3BlobStore blobStore; protected final String keyPath; - public AbstarctS3BlobContainer(BlobPath path, S3BlobStore blobStore) { + public AbstractS3BlobContainer(BlobPath path, S3BlobStore blobStore) { super(path); this.blobStore = blobStore; this.keyPath = path.buildAsString("/") + "/"; diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/S3ImmutableBlobContainer.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/S3ImmutableBlobContainer.java index aacefec03fa..90a74bdaabf 100644 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/S3ImmutableBlobContainer.java +++ b/plugins/cloud/aws/src/main/java/org/elasticsearch/cloud/aws/blobstore/S3ImmutableBlobContainer.java @@ -31,7 +31,7 @@ import java.io.InputStream; /** * @author kimchy (shay.banon) */ -public class S3ImmutableBlobContainer extends AbstarctS3BlobContainer implements ImmutableBlobContainer { +public class S3ImmutableBlobContainer extends AbstractS3BlobContainer implements ImmutableBlobContainer { public S3ImmutableBlobContainer(BlobPath path, S3BlobStore blobStore) { super(path, blobStore); diff --git a/plugins/cloud/aws/src/main/java/org/elasticsearch/gateway/s3/S3Gateway.java b/plugins/cloud/aws/src/main/java/org/elasticsearch/gateway/s3/S3Gateway.java index f86f48c6c3f..8a10e0280fa 100644 --- a/plugins/cloud/aws/src/main/java/org/elasticsearch/gateway/s3/S3Gateway.java +++ b/plugins/cloud/aws/src/main/java/org/elasticsearch/gateway/s3/S3Gateway.java @@ -52,6 +52,28 @@ public class S3Gateway extends BlobStoreGateway { } String region = componentSettings.get("region"); + if (region == null) { + if (settings.get("cloud.aws.region") != null) { + String regionSetting = settings.get("cloud.aws.region"); + if ("us-east".equals(regionSetting.toLowerCase())) { + region = null; + } else if ("us-east-1".equals(regionSetting.toLowerCase())) { + region = null; + } else if ("us-west".equals(regionSetting.toLowerCase())) { + region = "us-west-1"; + } else if ("us-west-1".equals(regionSetting.toLowerCase())) { + region = "us-west-1"; + } else if ("ap-southeast".equals(regionSetting.toLowerCase())) { + region = "ap-southeast-1"; + } else if ("ap-southeast-1".equals(regionSetting.toLowerCase())) { + region = "ap-southeast-1"; + } else if ("eu-west".equals(regionSetting.toLowerCase())) { + region = "EU"; + } else if ("eu-west-1".equals(regionSetting.toLowerCase())) { + region = "EU"; + } + } + } ByteSizeValue chunkSize = componentSettings.getAsBytesSize("chunk_size", new ByteSizeValue(100, ByteSizeUnit.MB)); logger.debug("using bucket [{}], region [{}], chunk_size [{}]", bucket, region, chunkSize);