import boto3 from botocore.exceptions import ClientError s3 = boto3.client('s3') try: response = s3.list_buckets() buckets = [bucket['Name'] for bucket in response['Buckets']] print("Bucket List: ", buckets) except ClientError as e: print("Error Message: ", e)
import botocore.session from botocore.exceptions import ClientError session = botocore.session.get_session() s3 = session.create_client('s3') try: response = s3.head_object(Bucket='my-bucket', Key='my-key') metadata = response['Metadata'] print("Object metadata: ", metadata) except ClientError as e: raise ValueError(f"Failed to access object metadata: {str(e)}")**Library:** The `botocore.exceptions.ClientError` is part of the `botocore` library.