"""COPIED FROM garcon-contrib 0.4.4rc0.""" def extract_bucket_path(url): """Extract the bucket name and path from the provided S3 url Args: url (str): S3 URL like 's3://bucket_name/folder1/folder2/' Return: tuple: bucket name and bucket path """ bucket_path = '' bucket_name = '' if url.startswith('s3://'): split_path = url.split('/', 3) bucket_name = split_path[2] if len(split_path) > 3: bucket_path = split_path[3] if not bucket_name: raise Exception('The S3 url \'{url}\' is not valid.'.format(url=url)) return (bucket_name, bucket_path)