(bucket_name)
return True, None
Check that we can write to a bucket.

    Returns (True, None) on success, (False, "fail message") if not writable

    Bucket existance check based on https://stackoverflow.com/a/47565719/10612
Check that we can write to a bucket.
Check that we can write to a bucket .
def check_bucket(bucket_name):
    """
    Check that we can write to a bucket.

    Returns (True, None) on success, (False, "fail message") if not writable

    Bucket existance check based on https://stackoverflow.com/a/47565719/10612
    """
    client = s3_client()

    # Test if we can see the bucket at all
    try:
        client.head_bucket(Bucket=bucket_name)
    except botocore.exceptions.ClientError as e:
        error_code = int(e.response["Error"]["Code"])
        if error_code == 403:
            return False, "Access forbidden"
        elif error_code == 404:
            return False, "Bucket does not exist"
        else:
            msg = (
                "Unknown error on head_bucket,"
                f" Code {e.response['Error']['Code']},"
                f" Message {e.response['Error']['Message']}"
            )
            return False, msg
    except botocore.exceptions.NoCredentialsError:
        return False, (
            "Unable to locate AWS credentials, see "
            "https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html"
        )

    # Create and delete a test file
    test_name = f"test-{uuid.uuid4()}"
    client.put_object(Bucket=bucket_name, Body=b"write test", Key=test_name)
    client.get_waiter("object_exists").wait(Bucket=bucket_name, Key=test_name)
    client.delete_object(Bucket=bucket_name, Key=test_name)
    client.get_waiter("object_not_exists").wait(Bucket=bucket_name, Key=test_name)

    return True, None
def check_bucket ( bucket_name ) : client = s3_client ( ) # Test if we can see the bucket at all try : client . head_bucket ( Bucket = bucket_name ) except botocore . exceptions . ClientError as e : error_code = int ( e . response [ "Error" ] [ "Code" ] ) if error_code == 403 : return False , "Access forbidden" elif error_code == 404 : return False , "Bucket does not exist" else : msg = ( "Unknown error on head_bucket," f" Code {e.response['Error']['Code']}," f" Message {e.response['Error']['Message']}" ) return False , msg except botocore . exceptions . NoCredentialsError : return False , ( "Unable to locate AWS credentials, see " "https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html" ) # Create and delete a test file test_name = f"test-{uuid.uuid4()}" client . put_object ( Bucket = bucket_name , Body = b"write test" , Key = test_name ) client . get_waiter ( "object_exists" ) . wait ( Bucket = bucket_name , Key = test_name ) client . delete_object ( Bucket = bucket_name , Key = test_name ) client . get_waiter ( "object_not_exists" ) . wait ( Bucket = bucket_name , Key = test_name ) return True , None