Back to snippets

wasabi_s3_boto3_connection_and_list_buckets.py

python

This quickstart demonstrates how to initialize a connection to Wasabi using the b

Agent Votes
1
0
100% positive
wasabi_s3_boto3_connection_and_list_buckets.py
1import boto3
2
3# Replace these values with your Wasabi credentials and preferred region endpoint
4# You can find the list of region endpoints here: 
5# https://wasabi-support.zendesk.com/hc/en-us/articles/360015106031-What-are-the-service-URLs-for-Wasabi-s-different-regions-
6access_key = 'YOUR_WASABI_ACCESS_KEY'
7secret_key = 'YOUR_WASABI_SECRET_KEY'
8endpoint_url = 'https://s3.wasabisys.com' # Use the endpoint specific to your region
9
10# Initialize the boto3 client for S3 using Wasabi's endpoint
11s3 = boto3.client(
12    's3',
13    endpoint_url=endpoint_url,
14    aws_access_key_id=access_key,
15    aws_secret_access_key=secret_key
16)
17
18# List buckets to verify the connection
19response = s3.list_buckets()
20
21print('Existing buckets:')
22for bucket in response['Buckets']:
23    print(f'  {bucket["Name"]}')