Skip to content

Commit 6c28811

Browse files
Remove silent fallbacks for env config options (#77)
1 parent 58544ce commit 6c28811

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ You can use the following environment variables for configuration:
4646
Useful when you have LocalStack bound to a different host (e.g., within docker-compose).
4747
* `LOCALSTACK_HOST` (deprecated): A <hostname>:<port> variable defining where to find LocalStack (default: localhost:4566).
4848
* `USE_SSL` (deprecated): Whether to use SSL when connecting to LocalStack (default: False).
49-
* `DEFAULT_REGION`: Set the default region. Overrides `AWS_DEFAULT_REGION` environment variable.
5049

5150
## Completion
5251

@@ -93,6 +92,7 @@ pip install https://github.com/boto/botocore/archive/v2.zip https://github.com/a
9392

9493
## Change Log
9594

95+
* v0.21: Use placeholder credentials and region only if Boto cannot not find them
9696
* v0.20: Small fixes for Python 2.x backward compatibility
9797
* v0.19: Patch botocore to skip adding `data-` host prefixes to endpoint URLs
9898
* v0.18: Pass `SYSTEMROOT` env variable to fix "_Py_HashRandomization_Init" error on Windows

bin/awslocal

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import subprocess
2323
import re
2424
from threading import Thread
2525

26+
from boto3.session import Session
27+
2628
PARENT_FOLDER = os.path.realpath(os.path.join(os.path.dirname(__file__), '..'))
2729
S3_VIRTUAL_ENDPOINT_HOSTNAME = 's3.localhost.localstack.cloud'
2830
if os.path.isdir(os.path.join(PARENT_FOLDER, '.venv')):
@@ -101,22 +103,19 @@ def prepare_environment():
101103
env_dict = os.environ.copy()
102104
env_dict['PYTHONWARNINGS'] = os.environ.get(
103105
'PYTHONWARNINGS', 'ignore:Unverified HTTPS request')
104-
if os.environ.get('DEFAULT_REGION'):
105-
if os.environ.get('AWS_DEFAULT_REGION'):
106-
msg = 'Environment variable "AWS_DEFAULT_REGION" will be overwritten by "DEFAULT_REGION"'
107-
print('INFO: %s' % msg)
108-
env_dict['AWS_DEFAULT_REGION'] = os.environ.get(
109-
'DEFAULT_REGION')
110-
else:
111-
env_dict['AWS_DEFAULT_REGION'] = os.environ.get(
112-
'AWS_DEFAULT_REGION', 'us-east-1')
113-
env_dict['AWS_ACCESS_KEY_ID'] = os.environ.get(
114-
'AWS_ACCESS_KEY_ID', 'test')
115-
env_dict['AWS_SECRET_ACCESS_KEY'] = os.environ.get(
116-
'AWS_SECRET_ACCESS_KEY', 'test')
117106

118107
env_dict.pop('AWS_DATA_PATH', None)
119108

109+
session = Session()
110+
credentials = session.get_credentials()
111+
112+
if not credentials:
113+
env_dict['AWS_ACCESS_KEY_ID'] = 'test'
114+
env_dict['AWS_SECRET_ACCESS_KEY'] = 'test'
115+
116+
if not session.region_name:
117+
env_dict['AWS_DEFAULT_REGION'] = 'us-east-1'
118+
120119
# update environment variables in the current process
121120
os.environ.update(env_dict)
122121

0 commit comments

Comments
 (0)