From 07417c16111424f07db571144f3414ed12520479 Mon Sep 17 00:00:00 2001 From: Ian Carroll Date: Sat, 2 Dec 2023 02:54:35 +0000 Subject: [PATCH] update for Amazon EC2 IMDSv2 --- CHANGELOG.md | 5 +++++ earthaccess/store.py | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) 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 f2f3618e..55e324ec 100644 --- a/earthaccess/store.py +++ b/earthaccess/store.py @@ -140,8 +140,10 @@ def _am_i_in_aws(self) -> bool: session = self.auth.get_session() try: # https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html - resp = session.get( - "http://169.254.169.254/latest/meta-data/public-ipv4", timeout=1 + resp = session.put( + "http://169.254.169.254/latest/api/token", + headers={"X-aws-ec2-metadata-token-ttl-seconds": "21600"}, + timeout=1, ) except Exception: return False