2

I'm attempting to use the python package awswrangler to access a non-AWS S3 service.

The AWS Data Wranger docs state that you need to create a boto3.Session() object.

The problem is that the boto3.client() supports setting the endpoint_url, but boto3.Session() does not (docs here).

In my previous uses of boto3 I've always used the client for this reason.

Is there a way to create a boto3.Session() with a custom endpoint_url or otherwise configure awswrangler to accept the custom endpoint?

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
David Parks
  • 30,789
  • 47
  • 185
  • 328

3 Answers3

5

I finally found the configuration for awswrangler:

import awswrangler as wr

wr.config.s3_endpoint_url = 'https://custom.endpoint'
David Parks
  • 30,789
  • 47
  • 185
  • 328
3

Any configuration variables for awswrangler can be overwritten directly using the wr.config config object as you stated in your answer, but it may be cleaner or preferable in some use cases to use environment variables.

In that case, simply set WR_S3_ENDPOINT_URL to your custom endpoint, and the configuration will reflect that when you import the library.

Bart Spoon
  • 93
  • 1
  • 7
2

Once you create your session, you can use client as well. For example:

import boto3

session = boto3.Session()
s3 = session.client('s3', endpoint_url='<custom-endpoint>')
jellycsc
  • 10,904
  • 2
  • 15
  • 32
Marcin
  • 215,873
  • 14
  • 235
  • 294
  • 2
    This didn't get the `endpoint_url` to pass through to `awswrangler` when `session` is handed to `awswrangler`. – David Parks Mar 25 '21 at 02:26
  • 1
    @DavidParks I think you should re-phrase your question, that you are asking only about `awswrangler as wr`. I answered to your original question regarding `Is there a way to create a boto3.Session() with a custom endpoint_url?` and the use of its client, not how do I modify `awswrangler` default endpoint. – Marcin Mar 25 '21 at 02:29
  • 2
    I agree, I was ambiguous about that, my fault. The `awswrangler` docs seemed very explicit that I should handle those matters in the session. I will update the wording. I do very much appreciate your answer and help. It got me past what I was stuck on and looking in the right area for the answer. – David Parks Mar 25 '21 at 02:32