No BotoCoreError to generate_presigned_url without an existing bucket
Lewiscowles1986 opened this issue · comments
Lewis Cowles commented
Reporting Bugs
Python version: 3.11.6
Moto version: 5.0.9
OS Version: OSX
Boto3 version: 1.34.122
Code
import boto3
from botocore.exceptions import BotoCoreError
from mypy_boto3_s3 import S3Client
def get_presigned_upload(bucket: str, key: str) -> str:
s3_client: S3Client = boto3.client('s3')
try:
presigned_response = s3_client.generate_presigned_url(
"put_object",
Params={"Bucket": "some-bucket", "Key": "Some Object"},
ExpiresIn=3600,
HttpMethod="PUT"
)
return presigned_response
except BotoCoreError:
print("oh good an error")
called (lets assume I imported directly
from wherever import get_presigned_upload
from moto import mock_aws
with mock_aws():
get_presigned_upload("bucket", "hello")
If using AWS I get errors trying to run this. NoCredentialsError is the specific, but any boto error will do. If I don't, regardless of the bucket existing or having access; code passes. Right now this means I'm calling list_objects_v2
which successfully errors when I attempt; with a ClientError.
Lewis Cowles commented
😊
with mock_aws(config={"core": {"mock_credentials": False}}):
Ah, so it just needs to mock credentials to get the same error as stock AWS