Skip to content

Commit 0cb20ae

Browse files
author
C. E. Brasseur
authored
Merge pull request #1980 from ceb8/mast_anonymous_aws
MAST: making AWS clous access anonymous
2 parents f365097 + f8bc527 commit 0cb20ae

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ mast
4343
- Added Zcut functionality to astroquery [#1911]
4444
- Fixed error causing empty products passed to ``Observations.get_product_list()`` to yeild a
4545
non-empty result. [#1921]
46+
- Changed AWS cloud access from RequesterPays to anonymous acces [#1980]
4647

4748
esa/hubble
4849
^^^^^^^^^^

astroquery/mast/cloud.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from astropy.logger import log
1515
from astropy.utils.console import ProgressBarOrSpinner
16+
from astropy.utils.exceptions import AstropyDeprecationWarning
1617

1718
from ..exceptions import NoResultsWarning, InvalidQueryError
1819

@@ -44,25 +45,24 @@ def __init__(self, provider="AWS", profile=None, verbose=False):
4445
Default False. Display extra info and warnings if true.
4546
"""
4647

48+
# Dealing with deprecated argument
49+
if profile is not None:
50+
warnings.warn(("MAST Open Data on AWS is now free to access and does "
51+
"not require an AWS account"), AstropyDeprecationWarning)
52+
4753
import boto3
4854
import botocore
4955

5056
self.supported_missions = ["mast:hst/product", "mast:tess/product", "mast:kepler"]
5157

52-
if profile is not None:
53-
self.boto3 = boto3.Session(profile_name=profile)
54-
else:
55-
self.boto3 = boto3
58+
self.boto3 = boto3
5659
self.botocore = botocore
60+
self.config = botocore.client.Config(signature_version=botocore.UNSIGNED)
5761

5862
self.pubdata_bucket = "stpubdata"
5963

6064
if verbose:
6165
log.info("Using the S3 STScI public dataset")
62-
log.warning("Your AWS account will be charged for access to the S3 bucket")
63-
log.info("See Request Pricing in https://aws.amazon.com/s3/pricing/ for details")
64-
log.info("If you have not configured boto3, follow the instructions here: "
65-
"https://boto3.readthedocs.io/en/latest/guide/configuration.html")
6666

6767
def is_supported(self, data_product):
6868
"""
@@ -110,7 +110,7 @@ def get_cloud_uri(self, data_product, include_bucket=True, full_url=False):
110110
found in the cloud, None is returned.
111111
"""
112112

113-
s3_client = self.boto3.client('s3')
113+
s3_client = self.boto3.client('s3', config=self.config)
114114

115115
path = utils.mast_relative_path(data_product["dataURI"])
116116
if path is None:
@@ -119,7 +119,7 @@ def get_cloud_uri(self, data_product, include_bucket=True, full_url=False):
119119
path = path.lstrip("/")
120120

121121
try:
122-
s3_client.head_object(Bucket=self.pubdata_bucket, Key=path, RequestPayer='requester')
122+
s3_client.head_object(Bucket=self.pubdata_bucket, Key=path)
123123
if include_bucket:
124124
path = "s3://{}/{}".format(self.pubdata_bucket, path)
125125
elif full_url:
@@ -172,8 +172,8 @@ def download_file(self, data_product, local_path, cache=True):
172172
Default is True. If file is found on disc it will not be downloaded again.
173173
"""
174174

175-
s3 = self.boto3.resource('s3')
176-
s3_client = self.boto3.client('s3')
175+
s3 = self.boto3.resource('s3', config=self.config)
176+
s3_client = self.boto3.client('s3', config=self.config)
177177
bkt = s3.Bucket(self.pubdata_bucket)
178178
with warnings.catch_warnings():
179179
warnings.simplefilter("ignore")
@@ -182,7 +182,7 @@ def download_file(self, data_product, local_path, cache=True):
182182
raise Exception("Unable to locate file {}.".format(data_product['productFilename']))
183183

184184
# Ask the webserver (in this case S3) what the expected content length is and use that.
185-
info_lookup = s3_client.head_object(Bucket=self.pubdata_bucket, Key=bucket_path, RequestPayer='requester')
185+
info_lookup = s3_client.head_object(Bucket=self.pubdata_bucket, Key=bucket_path)
186186
length = info_lookup["ContentLength"]
187187

188188
if cache and os.path.exists(local_path):
@@ -219,5 +219,4 @@ def progress_callback(numbytes):
219219
bytes_read += numbytes
220220
pb.update(bytes_read)
221221

222-
bkt.download_file(bucket_path, local_path, ExtraArgs={"RequestPayer": "requester"},
223-
Callback=progress_callback)
222+
bkt.download_file(bucket_path, local_path, Callback=progress_callback)

astroquery/mast/observations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ def download_file(self, uri, local_path=None, base_url=None, cache=True, cloud_o
539539
local_path = os.path.join(os.path.abspath('.'), filename)
540540

541541
# recreate the data_product key for cloud connection check
542-
data_product = {'dataURI': data_url}
542+
data_product = {'dataURI': uri}
543543

544544
status = "COMPLETE"
545545
msg = None

0 commit comments

Comments
 (0)