Skip to content

Commit aff06ce

Browse files
Merge pull request #12 from botanu-ai/developer-deborah
fix: remove hardcoded URLs and fix README badges
2 parents 3fb662c + 84d4697 commit aff06ce

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# Botanu SDK for Python
22

33
[![CI](https://github.com/botanu-ai/botanu-sdk-python/actions/workflows/ci.yml/badge.svg)](https://github.com/botanu-ai/botanu-sdk-python/actions/workflows/ci.yml)
4-
[![PyPI version](https://badge.fury.io/py/botanu.svg)](https://pypi.org/project/botanu/)
5-
[![Python versions](https://img.shields.io/pypi/pyversions/botanu.svg)](https://pypi.org/project/botanu/)
6-
[![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/botanu-ai/botanu-sdk-python/badge)](https://scorecard.dev/viewer/?uri=github.com/botanu-ai/botanu-sdk-python)
4+
[![PyPI version](https://img.shields.io/pypi/v/botanu)](https://pypi.org/project/botanu/)
5+
[![Python](https://img.shields.io/badge/python-3.9%20|%203.10%20|%203.11%20|%203.12%20|%203.13-blue)](https://www.python.org/)
76
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
87

98
OpenTelemetry-native **run-level cost attribution** for AI workflows.

src/botanu/resources/detector.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,30 @@ def _is_azure() -> bool:
182182

183183

184184
def _get_aws_availability_zone() -> Optional[str]:
185+
"""Get AWS availability zone from EC2 instance metadata.
186+
187+
Uses IMDS (Instance Metadata Service) which is only accessible from within EC2.
188+
Configure via environment variables:
189+
- AWS_EC2_METADATA_SERVICE_ENDPOINT: Override the metadata endpoint
190+
- AWS_EC2_METADATA_DISABLED: Set to 'true' to disable metadata calls
191+
"""
185192
if os.environ.get("AWS_LAMBDA_FUNCTION_NAME"):
186193
return None
194+
195+
# Respect AWS SDK standard env vars for disabling/configuring metadata
196+
if os.environ.get("AWS_EC2_METADATA_DISABLED", "").lower() == "true":
197+
return None
198+
199+
# Use AWS SDK standard endpoint override, or default to standard IMDS address
200+
endpoint = os.environ.get("AWS_EC2_METADATA_SERVICE_ENDPOINT", "http://169.254.169.254")
201+
if not endpoint or not endpoint.startswith(("http://", "https://")):
202+
return None
203+
187204
try:
188205
import urllib.request
189206

190-
req = urllib.request.Request(
191-
"http://169.254.169.254/latest/meta-data/placement/availability-zone",
192-
headers={"Accept": "text/plain"},
193-
)
207+
url = f"{endpoint}/latest/meta-data/placement/availability-zone"
208+
req = urllib.request.Request(url, headers={"Accept": "text/plain"}) # noqa: S310
194209
with urllib.request.urlopen(req, timeout=0.5) as resp: # noqa: S310
195210
return resp.read().decode("utf-8").strip()
196211
except Exception:

0 commit comments

Comments
 (0)