Skip to content

Commit 0b88005

Browse files
committed
replace us-west-2 check with boto3 functionality
1 parent 1a32eff commit 0b88005

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

earthaccess/store.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from typing import Any, Dict, List, Mapping, Optional, Tuple, Union
1010
from uuid import uuid4
1111

12+
import boto3
1213
import fsspec
1314
import requests
1415
import s3fs
@@ -140,26 +141,12 @@ def _own_s3_credentials(self, links: List[Dict[str, Any]]) -> Union[str, None]:
140141
return None
141142

142143
def _running_in_us_west_2(self) -> bool:
143-
session = self.auth.get_session()
144-
try:
145-
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
146-
token_ = session.put(
147-
"http://169.254.169.254/latest/api/token",
148-
headers={"X-aws-ec2-metadata-token-ttl-seconds": "21600"},
149-
timeout=1,
150-
)
151-
resp = session.get(
152-
"http://169.254.169.254/latest/meta-data/placement/region",
153-
timeout=1,
154-
headers={"X-aws-ec2-metadata-token": token_.text},
155-
)
156-
except Exception:
157-
return False
158-
159-
if resp.status_code == 200 and b"us-west-2" == resp.content:
160-
# On AWS in region us-west-2
144+
if (boto3.client('s3').meta.region_name == 'us-west-2'):
161145
return True
162-
return False
146+
else:
147+
raise ValueError('Your instance is not running inside the'
148+
' AWS us-west-2 region.'
149+
' You will not be able to directly access NASA Earthdata S3 buckets')
163150

164151
def set_requests_session(
165152
self, url: str, method: str = "get", bearer_token: bool = False

0 commit comments

Comments
 (0)