diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 915a8913..600c8027 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ ci: repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.3.0 + rev: v4.5.0 hooks: - id: check-yaml - id: trailing-whitespace diff --git a/CHANGELOG.md b/CHANGELOG.md index 223482d4..5c07deaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Unreleased + +* Bug fixes: + * Follow Amazon EC2 IMDSv2 requirements to set `running-in-aws` + ## [v0.8.1] 2023-12-01 * New Features: * Add `kerchunk` metadata consolidation utility. diff --git a/earthaccess/store.py b/earthaccess/store.py index 77ba518a..645721ad 100644 --- a/earthaccess/store.py +++ b/earthaccess/store.py @@ -143,8 +143,15 @@ def _running_in_us_west_2(self) -> bool: session = self.auth.get_session() try: # https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html + token_ = session.put( + "http://169.254.169.254/latest/api/token", + headers={"X-aws-ec2-metadata-token-ttl-seconds": "21600"}, + timeout=1, + ) resp = session.get( - "http://169.254.169.254/latest/meta-data/placement/region", timeout=1 + "http://169.254.169.254/latest/meta-data/placement/region", + timeout=1, + headers={"X-aws-ec2-metadata-token": token_.text}, ) except Exception: return False