Skip to content

Commit dc14659

Browse files
authored
Merge pull request drivendataorg#71 from pmh-ds/master
Added support for multiple AWS profiles
2 parents 3e0dbed + 934a98c commit dc14659

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ docs/site/
22

33
# OSX Junk
44
.DS_Store
5+
6+
# test cache
7+
.cache/*
8+
tests/__pycache__/*

cookiecutter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"description": "A short description of the project.",
66
"open_source_license": ["MIT", "BSD", "Not open source"],
77
"s3_bucket": "[OPTIONAL] your-bucket-for-syncing-data (do not include 's3://')",
8+
"aws_profile": "default",
89
"python_interpreter": ["python", "python3"]
910
}

docs/docs/index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,19 @@ database_url = os.environ.get("DATABASE_URL")
215215
other_variable = os.environ.get("OTHER_VARIABLE")
216216
```
217217

218+
#### AWS CLI configuration
219+
When using Amazon S3 to store data, a simple method of managing AWS access is to set your access keys to environment variables. However, managing mutiple sets of keys on a single machine (e.g. when working on multiple projects) it is best to use a [credentials file](https://docs.aws.amazon.com/cli/latest/userguide/cli-config-files.html), typically located in `~/.aws/credentials`. A typical file might look like:
220+
```
221+
[default]
222+
aws_access_key_id=myaccesskey
223+
aws_secret_access_key=mysecretkey
224+
225+
[another_project]
226+
aws_access_key_id=myprojectaccesskey
227+
aws_secret_access_key=myprojectsecretkey
228+
```
229+
You can add the profile name when initialising a project; assuming no applicable environment variables are set, the profile credentials will be used be default.
230+
218231
### Be conservative in changing the default folder structure
219232

220233
To keep this structure broadly applicable for many different kinds of projects, we think the best approach is to be liberal in changing the folders around for _your_ project, but be conservative in changing the default structure for _all_ projects.

tests/test_creation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ def test_folders(default_baked_project):
8080
]
8181

8282
ignored_dirs = [
83-
default_baked_project,
84-
os.path.join(default_baked_project, '__pycache__')
83+
default_baked_project
8584
]
8685

8786
abs_expected_dirs = [os.path.join(default_baked_project, d) for

{{ cookiecutter.repo_name }}/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
PROJECT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
88
BUCKET = {{ cookiecutter.s3_bucket }}
9+
PROFILE = {{ cookiecutter.aws_profile }}
910
PROJECT_NAME = {{ cookiecutter.repo_name }}
1011
PYTHON_INTERPRETER = {{ cookiecutter.python_interpreter }}
1112

@@ -37,11 +38,19 @@ lint:
3738

3839
## Upload Data to S3
3940
sync_data_to_s3:
41+
ifeq (default,$(PROFILE))
4042
aws s3 sync data/ s3://$(BUCKET)/data/
43+
else
44+
aws s3 sync data/ s3://$(BUCKET)/data/ --profile $(PROFILE)
45+
endif
4146

4247
## Download Data from S3
4348
sync_data_from_s3:
49+
ifeq (default,$(PROFILE))
4450
aws s3 sync s3://$(BUCKET)/data/ data/
51+
else
52+
aws s3 sync s3://$(BUCKET)/data/ data/ --profile $(PROFILE)
53+
endif
4554

4655
## Set up python interpreter environment
4756
create_environment:

0 commit comments

Comments
 (0)