s3 urls - get bucket name and path

后端 未结 7 810
南方客
南方客 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:56

    If you want to do it with regular expressions, you can do the following:

    >>> import re
    >>> uri = 's3://my-bucket/my-folder/my-object.png'
    >>> match = re.match(r's3:\/\/(.+?)\/(.+)', uri)
    >>> match.group(1)
    'my-bucket'
    >>> match.group(2)
    'my-folder/my-object.png'
    

    This has the advantage that you can check for the s3 scheme rather than allowing anything there.

    0 讨论(0)
提交回复
热议问题