-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Default ec2 endpoint is ec2.us-east-1.amazonaws.com #27925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
97e9e09
a4d35ca
8f60084
2dbfdd7
4e2e981
530d885
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,12 +23,14 @@ | |
| import com.amazonaws.auth.AWSCredentials; | ||
| import com.amazonaws.auth.AWSCredentialsProvider; | ||
| import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; | ||
| import com.amazonaws.client.builder.AwsClientBuilder; | ||
| import com.amazonaws.http.IdleConnectionReaper; | ||
| import com.amazonaws.internal.StaticCredentialsProvider; | ||
| import com.amazonaws.regions.InstanceMetadataRegionProvider; | ||
| import com.amazonaws.retry.RetryPolicy; | ||
| import com.amazonaws.services.ec2.AmazonEC2; | ||
| import com.amazonaws.services.ec2.AmazonEC2Client; | ||
|
|
||
| import com.amazonaws.services.ec2.AmazonEC2ClientBuilder; | ||
| import com.amazonaws.util.AwsHostNameUtils; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.elasticsearch.ElasticsearchException; | ||
|
|
@@ -40,7 +42,7 @@ | |
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| class AwsEc2ServiceImpl implements AwsEc2Service { | ||
|
|
||
| private static final Logger logger = LogManager.getLogger(AwsEc2ServiceImpl.class); | ||
|
|
||
| private final AtomicReference<LazyInitializable<AmazonEc2Reference, ElasticsearchException>> lazyClientReference = | ||
|
|
@@ -49,20 +51,50 @@ class AwsEc2ServiceImpl implements AwsEc2Service { | |
| private AmazonEC2 buildClient(Ec2ClientSettings clientSettings) { | ||
| final AWSCredentialsProvider credentials = buildCredentials(logger, clientSettings); | ||
| final ClientConfiguration configuration = buildConfiguration(logger, clientSettings); | ||
| final AmazonEC2 client = buildClient(credentials, configuration); | ||
|
|
||
| final AwsClientBuilder.EndpointConfiguration endpointConfiguration; | ||
| if (Strings.hasText(clientSettings.endpoint)) { | ||
| logger.debug("using explicit ec2 endpoint [{}]", clientSettings.endpoint); | ||
| client.setEndpoint(clientSettings.endpoint); | ||
| endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(clientSettings.endpoint, | ||
| buildRegion(clientSettings.endpoint)); | ||
| } else { | ||
| logger.debug("No endpoint defined. Using default endpoint [ec2.us-east-1.amazonaws.com]."); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When using the This seems like a good default to use, but is a breaking change. See general review comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @henningandersen @DaveCTurner @dadoonet Hello All, We are looking for multiple region ec2-discovery option. Can you please update where are we with the below comment. Is it already implemented and in-use or its gonna be in future release ? Given that this is potentially a breaking change (with master nodes in us-east-1 and data nodes in some other region, the data nodes will no longer be able to discover the master nodes) Thanks
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @suganselvaraj this is still outstanding, i.e., not implemented into master or any releases yet.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that:
This is not something we really support AFAIK. You should have all nodes within the same region for latency reasons. My 2 cents. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @suganselvaraj I think it will not work using "ec2-discovery" because under the hood it's searching for nodes inside the same aws region. You can use a fixed list of IP's, but it can cause latency issues. |
||
| endpointConfiguration = null; | ||
| } | ||
|
|
||
| final AmazonEC2 client = buildClient(credentials, configuration, endpointConfiguration); | ||
| return client; | ||
| } | ||
|
|
||
| // proxy for testing | ||
| AmazonEC2 buildClient(AWSCredentialsProvider credentials, ClientConfiguration configuration) { | ||
| final AmazonEC2 client = new AmazonEC2Client(credentials, configuration); | ||
| AmazonEC2 buildClient(AWSCredentialsProvider credentials, ClientConfiguration configuration, | ||
| AwsClientBuilder.EndpointConfiguration endpointConfiguration) { | ||
|
|
||
| AmazonEC2ClientBuilder builder = AmazonEC2ClientBuilder.standard() | ||
| .withCredentials(credentials) | ||
| .withClientConfiguration(configuration); | ||
| if (endpointConfiguration != null) { | ||
| builder.setEndpointConfiguration(endpointConfiguration); | ||
| } | ||
| final AmazonEC2 client = builder.build(); | ||
| return client; | ||
| } | ||
|
|
||
| // Package private for tests | ||
| static String buildRegion(String endpoint) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should get the region from the endpoint or if endpoint is not set, simply return null. Ie. we do not really need to lookup the region using the |
||
| // We try to get the region from the metadata instance information | ||
| String region = new InstanceMetadataRegionProvider().getRegion(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we only be inferring this if the endpoint is not set?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That should come in another PR related to #27924 IMO. Make sense? |
||
| if (region == null) { | ||
| // Or we try to get it from the endpoint itself | ||
| region = AwsHostNameUtils.parseRegion(endpoint, null); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we need to check for null again here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah! Good catch. Indeed the AWS implementation returns null. I'm going to add this. Thanks |
||
| if (region == null) { | ||
| // Endpoint is non-standard | ||
| throw new IllegalArgumentException("Can not guess a region from endpoint [" + endpoint + "]."); | ||
| } | ||
| } | ||
| return region; | ||
| } | ||
|
|
||
| // pkg private for tests | ||
| static ClientConfiguration buildConfiguration(Logger logger, Ec2ClientSettings clientSettings) { | ||
| final ClientConfiguration clientConfiguration = new ClientConfiguration(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand it, the region and endpoint has to go together and really specifying the endpoint should not be done. The region is used to determine signing as well, which means that using a wrong region for an endpoint is unlikely to work (AFAIK). Given that we calculate the region from the endpoint anyway, we may as well just call
AwsClientBuilder.withRegionwith the region, this will ensure both the endpoint and signing region are set.