s3 urls - get bucket name and path

后端 未结 7 823
南方客
南方客 2020-12-13 23:20

I have a variable which has the aws s3 url

s3://bucket_name/folder1/folder2/file1.json

I want to get the bucket_name in a variables and re

7条回答
  •  孤城傲影
    2020-12-13 23:42

    Here it is as a one-liner using regex:

    import re
    
    s3_path = "s3://bucket/path/to/key"
    
    bucket, key = re.match(r"s3:\/\/(.+?)\/(.+)", s3_path).groups()
    

提交回复
热议问题