def find_bucket_key(s3_path):
"""
This is a helper function that given an s3 path such that the path is of
the form: bucket/key
It will return the bucket and the key represented by the s3 path
"""
s3_components = s3_path.split('/')
bucket = s3_components[0]
s3_key = ""
if len(s3_components) > 1:
s3_key = '/'.join(s3_components[1:])
return bucket, s3_key
def split_s3_bucket_key(s3_path):
"""Split s3 path into bucket and key prefix.
This will also handle the s3:// prefix.
:return: Tuple of ('bucketname', 'keyname')
"""
if s3_path.startswith('s3://'):
s3_path = s3_path[5:]
return find_bucket_key(s3_path)
对于开场白,应该简单到:
如果文件是公共的,这将适用于s3。
要使用boto编写文件,可以这样做:
让我知道这对你是否有效:)
我还没有看到可以直接使用s3url的东西,但是可以使用S3 access library(simples3看起来不错)和一些简单的字符串操作:
Here's how they do在awscli中:
你可以用这样的代码
这并没有将与s3键交互作为file like object的目标,但这是朝着这个方向迈出的一步。
相关问题 更多 >
编程相关推荐