Skip to content

Automatically guess EC2 endpoint based on metadata #27924

@dadoonet

Description

@dadoonet

While I was working on #27464, I came to this part of the AWS SDK code:

    /**
     * Sets the endpoint configuration (service endpoint & signing region) to be used for requests. If neither region {@link #setRegion(String)}
     * or endpoint configuration are explicitly provided in the builder the {@link #DEFAULT_REGION_PROVIDER} is consulted.
     *
     * <p><b>Only use this if using a non-standard service endpoint - the recommended approach for configuring a client is to use {@link #setRegion(String)}</b>
     *
     * @param endpointConfiguration The endpointConfiguration to use
     */
    public final void setEndpointConfiguration(EndpointConfiguration endpointConfiguration) {
        withEndpointConfiguration(endpointConfiguration);
    }

Important part is:

Only use this if using a non-standard service endpoint - the recommended approach for configuring a client is to use setRegion(String)

Which basically means that we should revisit the decision we made in #22758 and remove endpoint and reintroduce region.

Creating a AWS EC2 client would be as simple as:

        AmazonEC2ClientBuilder builder = AmazonEC2ClientBuilder.standard()
            .withRegion(region)
            .withCredentials(buildCredentials(logger, settings))
            .withClientConfiguration(buildConfiguration(logger, settings));

Even better, we can actually retrieve automatically the region if not explicitly set from the metadata instance by calling:

String region = new InstanceMetadataRegionProvider().getRegion();

Which would simplify even more the usage of the plugin as people won't normally have to define anything but:

discovery.zen.hosts_provider: ec2

Authentication is done using IAM Role credentials by default.

@rjernst @tlrx thoughts?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions