-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_s3.py
More file actions
53 lines (39 loc) · 1.26 KB
/
check_s3.py
File metadata and controls
53 lines (39 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Quick script to verify AWS S3 credentials and permissions.
Run with: uv run check_s3.py
This checks that your .env credentials can upload to and delete from your S3 bucket
without needing to go through the full application flow.
"""
from io import BytesIO
from botocore.exceptions import BotoCoreError, ClientError
from config import settings
from image_utils import _get_s3_client
def check_s3_connection():
s3 = _get_s3_client()
print(f"Bucket: {settings.s3_bucket_name}")
print(f"Region: {settings.s3_region}")
print()
test_key = "profile_pics/test.txt"
# Test upload
try:
s3.upload_fileobj(
BytesIO(b"test"),
settings.s3_bucket_name,
test_key,
ExtraArgs={"ContentType": "text/plain"},
)
print("Upload: SUCCESS")
except (BotoCoreError, ClientError) as e:
print(f"Upload: FAILED - {e}")
return
# Test delete
try:
s3.delete_object(Bucket=settings.s3_bucket_name, Key=test_key)
print("Delete: SUCCESS")
except (BotoCoreError, ClientError) as e:
print(f"Delete: FAILED - {e}")
return
print()
print("All tests passed! Your S3 configuration is working.")
if __name__ == "__main__":
check_s3_connection()