-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
boto3 set endpoint_url from environment variables #1375
Comments
I found a workaround to do that as below for boto3. But it would be better if it was as above from boto3 import Session |
You can set this during client creation as an argument. Documented here. There is no environment variable for this but there is nothing stopping you from looking in |
Closing as dupe of aws/aws-cli#1270 |
Could you please reopen this issue? This feature isn't supported currently in boto3. The dup of aws/aws-cli#1270 has been fixed by an awscli plugin https://github.com/wbingli/awscli-plugin-endpoint But it only works with aws cli. It seems the same feature has been added in php sdk as well https://github.com/aws/aws-sdk-php/pull/1243/files/aeb25899897fe746580ae6c80e0df6ad37931126 If it can work with aws config profile file directly, better than implemented with environment variables, because one python functions can use different endpoint for different aws services.
|
For those interested in a workaround until this feature is implemented, see aws/aws-cli#1270 (comment) |
I've added a PR to provide this #2746. |
Can we please get this re-opened? Its a widely requested feature, with a simple, two line implementation that has been languishing in a ready to merge state for nearly a year here: #2746 |
If you need to temporarily patch something in a test, this how you can do it with from unittest.mock import patch
import boto3
from botocore.client import Config
patched_defaults = (
"us-east-1", # region_name
None, # api_version
True, # use_ssl
None, # verify
"http://localhost:9000", # endpoint_url
"minioadmin", # aws_access_key_id
"minioadmin", # aws_secret_access_key
None, # aws_session_token
Config(signature_version="s3v4"), # config
)
with patch.object(boto3.session.Session.resource, "__defaults__", patched_defaults):
session = Session()
s3 = session.resource("s3")
# proceed as needed You can also patch |
I also faced this problem, and since #2746 seems to be in limbo, and aws/aws-sdk/issues/229 is only a proposal, I went ahead an build a little SHIM to provide the proposal's base functionality (specific env vars and nested config). EDIT (2022-12-22) I have implemented the proposal in a workaround package: boto-endpoint-url-shim. Base usage for service-specific environment variable and service subsection in shared configuration file: import boto_endpoint_url_shim
import boto3
boto_endpoint_url_shim.proposed_endpoint_url_resolution()
s3 = boto3.resource("s3") # uses the custom endpoint This is my first public python package and it is in early stages, but it implements all the proposed endpoint resolution methods. If you have any feedback, feel free to drop me a message or open an issue on gitlab. |
FYI, #2746 was closed due to boto3 directly implementing this feature. With |
Could you please advise how to set endpoint_url outside of the code by setting an environment variable or a ~/.aws/config file?
The text was updated successfully, but these errors were encountered: