Skip to content
Snippets Groups Projects
Commit c4735d9c authored by Gavin M. Roy's avatar Gavin M. Roy
Browse files

Cleanup a few things, add AWS_DEFAULT_REGION

- Add support for AWS_DEFAULT_REGION
- Cleanup retry requests
- Ensure HTTPClient usage is new and not out of a shared pool
parent dd4e6123
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -3,6 +3,12 @@
Version History
===============
 
0.4.0 (2016-02-05)
------------------
- Add support for the AWS_DEFAULT_REGION environment variable.
- Cleanup retry requests
- Ensure HTTPClient usage is new and not out of a shared pool
0.3.0 (2016-02-03)
------------------
- Make authentication work with EC2 Instance metadata, add async support for credential fetching.
Loading
Loading
Loading
Loading
@@ -21,7 +21,7 @@ DESC = 'A low-level Amazon Web Services API client for Tornado'
TESTS_REQUIRE = ['nose', 'mock', 'coverage']
 
setuptools.setup(name='tornado-aws',
version='0.3.0',
version='0.4.0',
description=DESC,
long_description=open('README.rst').read(),
author='Gavin M. Roy',
Loading
Loading
Loading
Loading
@@ -6,6 +6,6 @@ from tornado_aws.client import AWSClient
from tornado_aws.client import AsyncAWSClient
from tornado_aws.client import exceptions
 
__version__ = '0.3.0'
__version__ = '0.4.0'
 
__all__ = ['AWSClient', 'AsyncAWSClient', 'exceptions']
Loading
Loading
@@ -51,6 +51,11 @@ class AWSClient(object):
``AWSClient`` instance or by setting the ``AWS_DEFAULT_PROFILE``
environment variable. If neither are set, ``default`` will be used.
 
The AWS region is set by reading in configuration or by the
``AWS_DEFAULT_REGION`` environment variable. If neither or set, it will
attempt to be set by invoking the EC2 Instance Metadata and user data API,
if available.
The AWS access key can be set when creating a new instance. If it's not
passed in when creating the ``AWSClient``, the client will attempt to
get the key from the ``AWS_ACCESS_KEY_ID`` environment variable. If that is
Loading
Loading
@@ -101,7 +106,6 @@ class AWSClient(object):
secret_key, self._client)
self._endpoint_url = self._endpoint(endpoint)
self._host = self._hostname(self._endpoint_url)
self._retrying_request = False
 
def fetch(self, method, path='/', query_args=None, headers=None, body=b'',
_recursed=False):
Loading
Loading
@@ -130,18 +134,16 @@ class AWSClient(object):
 
try:
result = self._client.fetch(request, raise_error=True)
self._retrying_request = False
return result
except httpclient.HTTPError as error:
awz_error = self._awz_error(error)
if awz_error:
if self._credentials_error(awz_error):
if not self._auth_config.local_credentials:
if not self._retrying_request:
if not _recursed:
self._auth_config.refresh()
self._retrying_request = True
return self.fetch(method, path, query_args,
headers, body)
headers, body, True)
else:
self._auth_config.reset()
 
Loading
Loading
@@ -220,7 +222,7 @@ class AWSClient(object):
:rtype: :py:class:`tornado.httpclient.HTTPClient`
 
"""
return httpclient.HTTPClient()
return httpclient.HTTPClient(force_instance=True)
 
@staticmethod
def _hostname(url):
Loading
Loading
Loading
Loading
@@ -37,6 +37,10 @@ def get_region(profile):
:raises: exceptions.ConfigNotFound
 
"""
region = os.getenv('AWS_DEFAULT_REGION', None)
if region:
return region
file_path = os.getenv('AWS_CONFIG_FILE', '~/.aws/config')
try:
config = _parse_file(file_path)
Loading
Loading
@@ -91,7 +95,7 @@ def _request_region_from_instance():
 
"""
url = INSTANCE_ENDPOINT.format(REGION_PATH)
client = httpclient.HTTPClient()
client = httpclient.HTTPClient(force_instance=True)
response = client.fetch(url,
connect_timeout=HTTP_TIMEOUT,
request_timeout=HTTP_TIMEOUT)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment