Skip to content

Respect endpoints provided via AWS profiles or environment variables #269

@jacobemcken

Description

@jacobemcken

I can already provide region and credentials via AWS profiles or environment variables — awesome — thank you 🙏 .
I would love to be able to provide endpoints the same way.

This would let me reuse the same configuration for CLI tools and code, which is especially helpful in local development environments.

AWS profiles can specify endpoints like so:

[profile dev]
endpoint_url = http://localhost:1234
services = s3-specific

[services s3-specific]
s3 = 
  endpoint_url = http://localhost:4567

Source: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html#cli-config-endpoint_url

Similarly, an endpoint can be overwritten/provided by the following environment variables:

AWS_ENDPOINT_URL
AWS_ENDPOINT_URL_<SERVICE>

Source: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html#envvars-list-AWS_ENDPOINT_URL

For example, I often use Minio for local S3-compatible development. But I end up writing code like this to conditionally support both local and AWS environments:

(defn uri->map
  "Convenience function for providing a single connection URL over multiple
   individual properties."
  [uri]
  (let [uri-obj (URI. uri)]
    {:scheme (.getScheme uri-obj)
     :host (.getHost uri-obj)
     :port (.getPort uri-obj)}))

(defn create-client
  "Takes a connection URI to reduce the amount of config to inject"
  [endpoint-uri]
  (let [{:keys [scheme host port] :as endpoint} (some-> endpoint-uri uri->map)]
    (cond-> {:api :s3}
      endpoint (assoc :endpoint-override {:protocol (keyword scheme)
                                          :hostname host
                                          :port port})
      :always (aws/client))))

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    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