Skip to content

Commit 254ef0e

Browse files
committed
Fix bugs in sync data
1 parent b82006f commit 254ef0e

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ sync_data_to_s3:
5555

5656
## Download Data from S3
5757
sync_data_from_s3:
58-
$(PYTHON_INTERPRETER) -m dengue_prediction.data.sync_data upload
58+
$(PYTHON_INTERPRETER) -m dengue_prediction.data.sync_data download
5959

6060
## Set up python interpreter environment
6161
create_environment:

config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ problem:
77

88
data:
99
s3_bucket: mit-dai-micahs-misc
10+
s3_bucket_region: us-east-1
1011
train: data/raw
1112
entities_table_name: dengue_features
1213
target_table_name: dengue_labels

dengue_prediction/data/sync_data.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,28 @@ def get_s3_base_url():
2020
def run_aws_s3_sync(src, dst, credentials=True, profile=None):
2121
cmd = ['aws', 's3', 'sync']
2222
if not credentials:
23-
cmd.append('--no-sign-request')
24-
region = 'us-east-1'
23+
cmd.insert(1, '--no-sign-request')
24+
region = cg('data', 's3_bucket_region')
2525
cmd.append('--region={}'.format(region))
26+
cmd.append('--source-region={}'.format(region))
2627
cmd.append(src)
2728
cmd.append(dst)
2829
if profile is not None:
2930
cmd.append('--profile')
3031
cmd.append(profile)
3132
try:
32-
output = subprocess.check_output(cmd, universal_newlines=True)
33+
logger.debug('Executing command: {}'.format(' '.join(cmd)))
34+
output = subprocess.check_output(
35+
cmd, universal_newlines=True, stderr=subprocess.STDOUT)
3336
if output:
3437
logger.info(output)
3538
return output
3639
except subprocess.CalledProcessError as e:
37-
if 'Unable to locate credentials' in e.output:
38-
if credentials:
39-
return run_aws_s3_sync(
40-
src, dst, credentials=False, profile=profile)
40+
if 'Unable to locate credentials' in e.output and credentials:
41+
return run_aws_s3_sync(
42+
src, dst, credentials=False, profile=profile)
43+
else:
44+
raise
4145

4246

4347
def upload(profile=None):

0 commit comments

Comments
 (0)