"""Logic for s3.""" from functools import cache import json from urllib.parse import urlparse import boto3 from src import config @cache def get_client(): """Get s3 client.""" return boto3.client('s3', config.AWS_REGION) def fetch_product_metadata(s3_url): """Fetch product metadata from S3.""" parsed = urlparse(s3_url) bucket = parsed.netloc key = parsed.path.lstrip('/') s3_client = get_client() response = s3_client.get_object(Bucket=bucket, Key=key) return json.loads(response['Body'].read())