-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Nordstrom/boto
0.2.0
- Loading branch information
Showing
7 changed files
with
196 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [0.2.0] - 2019-01-02 | ||
### Added | ||
- Informative error message for the env_var argument in the `redshift_execute()` and `redshift_get_conn()` functions | ||
- A `boto_get_creds()` function was created to allow the user to obtain credentials strings for purposes such as `COPY` and `UNLOAD` SQL statements | ||
- Version documentation in the `CHANGELOG.md` file | ||
### Changed | ||
- The `create_session()` function was renamed to `boto_create_session()` to highlight that the session object can be used to access a wide variety of AWS tools | ||
|
||
## [0.1.1] - 2018-12-14 | ||
### Fixed | ||
- Docstrings and `README.md` documentation for S3 functions | ||
|
||
## [0.1] - 2018-12-11 | ||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
'''Convenience wrappers for connecting to AWS S3 and Redshift''' | ||
|
||
__version__ = '0.1.1' | ||
__version__ = '0.2.0' | ||
|
||
|
||
# Boto3 function | ||
from ._boto import boto_get_creds | ||
from ._boto import boto_create_session | ||
# Redshift functions | ||
from ._redshift import redshift_get_conn | ||
from ._redshift import read_sql | ||
from ._redshift import redshift_execute_sql | ||
# S3 functions | ||
from ._s3 import create_session | ||
from ._s3 import s3_get_bucket | ||
from ._s3 import s3_download | ||
from ._s3 import s3_upload | ||
from ._s3 import s3_delete | ||
|
||
|
||
__all__ = ['_redshift', '_s3'] | ||
__all__ = ['_boto', '_redshift', '_s3'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import boto3 | ||
|
||
|
||
def boto_create_session(profile_name='default', region_name='us-west-2'): | ||
""" Instantiates and returns a boto3 session object | ||
Parameters | ||
---------- | ||
profile_name : str | ||
profile name under which credentials are stored (default 'default' unless organization specific) | ||
region_name : str | ||
name of AWS regions (default 'us-west-2') | ||
Returns | ||
------- | ||
boto3 session object | ||
Example use | ||
----------- | ||
session = create_session(profile_name='default', region_name='us-west-2') | ||
""" | ||
return boto3.session.Session(profile_name=profile_name, region_name=region_name) | ||
|
||
|
||
def boto_get_creds( | ||
profile_name='default', | ||
region_name='us-west-2', | ||
session=None): | ||
""" Generates and returns an S3 credential string | ||
Parameters | ||
---------- | ||
profile_name : str | ||
profile name under which credentials are stores (default 'default' unless organization specific) | ||
region_name : str | ||
name of AWS regions (default 'us-west-2') | ||
session : boto3 session object or None | ||
you can optionally provide a boto3 session object or the function can instantiate a new one if None | ||
Returns | ||
------- | ||
str | ||
credentials for accessing S3 | ||
Example use | ||
----------- | ||
creds = boto_get_creds( | ||
profile_name='default', | ||
region_name='us-west-2', | ||
session=None) | ||
""" | ||
if session is None: | ||
session = boto_create_session(profile_name=profile_name, region_name=region_name) | ||
access_key = session.get_credentials().access_key | ||
secret_key = session.get_credentials().secret_key | ||
token = session.get_credentials().token | ||
return f'''aws_access_key_id={access_key};aws_secret_access_key={secret_key};token={token}''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# TODO: write boto_get_creds() tests (types, errors, and str contents) | ||
import boto3 | ||
from ..nordata import _boto as bt | ||
|
||
|
||
def test_boto_create_session_type(): | ||
# test whether _create_session() returns the proper type | ||
assert isinstance(bt.boto_create_session(), boto3.session.Session) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters