s3 signature fix

This commit is contained in:
Hridayesh Gupta 2026-05-19 13:07:47 +05:30
parent 3477714554
commit 542a3ddb5d

View file

@ -1,6 +1,7 @@
from typing import Any, BinaryIO, Dict, Optional from typing import Any, BinaryIO, Dict, Optional
import aioboto3 import aioboto3
from botocore.config import Config
from botocore.exceptions import ClientError from botocore.exceptions import ClientError
from .base import BaseFileSystem from .base import BaseFileSystem
@ -19,11 +20,12 @@ class S3FileSystem(BaseFileSystem):
self.bucket_name = bucket_name self.bucket_name = bucket_name
self.region_name = region_name self.region_name = region_name
self.session = aioboto3.Session() self.session = aioboto3.Session()
self.config = Config(signature_version="s3v4")
async def acreate_file(self, file_path: str, content: BinaryIO) -> bool: async def acreate_file(self, file_path: str, content: BinaryIO) -> bool:
try: try:
async with self.session.client( async with self.session.client(
"s3", region_name=self.region_name "s3", region_name=self.region_name, config=self.config
) as s3_client: ) as s3_client:
await s3_client.put_object( await s3_client.put_object(
Bucket=self.bucket_name, Key=file_path, Body=await content.read() Bucket=self.bucket_name, Key=file_path, Body=await content.read()
@ -35,7 +37,7 @@ class S3FileSystem(BaseFileSystem):
async def aupload_file(self, local_path: str, destination_path: str) -> bool: async def aupload_file(self, local_path: str, destination_path: str) -> bool:
try: try:
async with self.session.client( async with self.session.client(
"s3", region_name=self.region_name "s3", region_name=self.region_name, config=self.config
) as s3_client: ) as s3_client:
await s3_client.upload_file( await s3_client.upload_file(
local_path, self.bucket_name, destination_path local_path, self.bucket_name, destination_path
@ -60,7 +62,7 @@ class S3FileSystem(BaseFileSystem):
""" """
try: try:
async with self.session.client( async with self.session.client(
"s3", region_name=self.region_name "s3", region_name=self.region_name, config=self.config
) as s3_client: ) as s3_client:
params = {"Bucket": self.bucket_name, "Key": file_path} params = {"Bucket": self.bucket_name, "Key": file_path}
@ -101,7 +103,7 @@ class S3FileSystem(BaseFileSystem):
"""Get S3 object metadata.""" """Get S3 object metadata."""
try: try:
async with self.session.client( async with self.session.client(
"s3", region_name=self.region_name "s3", region_name=self.region_name, config=self.config
) as s3_client: ) as s3_client:
response = await s3_client.head_object( response = await s3_client.head_object(
Bucket=self.bucket_name, Key=file_path Bucket=self.bucket_name, Key=file_path
@ -127,7 +129,7 @@ class S3FileSystem(BaseFileSystem):
"""Generate a presigned PUT URL for direct file upload.""" """Generate a presigned PUT URL for direct file upload."""
try: try:
async with self.session.client( async with self.session.client(
"s3", region_name=self.region_name "s3", region_name=self.region_name, config=self.config
) as s3_client: ) as s3_client:
url = await s3_client.generate_presigned_url( url = await s3_client.generate_presigned_url(
"put_object", "put_object",
@ -146,7 +148,7 @@ class S3FileSystem(BaseFileSystem):
"""Download a file from S3 to local path.""" """Download a file from S3 to local path."""
try: try:
async with self.session.client( async with self.session.client(
"s3", region_name=self.region_name "s3", region_name=self.region_name, config=self.config
) as s3_client: ) as s3_client:
await s3_client.download_file(self.bucket_name, source_path, local_path) await s3_client.download_file(self.bucket_name, source_path, local_path)
return True return True