Skip to content

Commit 11c4ff5

Browse files
Add S3 Object Lambda ARN and S3 Outposts ARN (#686)
Co-authored-by: Martin Durant <[email protected]>
1 parent 9bf99f7 commit 11c4ff5

2 files changed

Lines changed: 27 additions & 15 deletions

File tree

‎s3fs/core.py‎

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -377,20 +377,29 @@ def _find_bucket_key(self, s3_path):
377377
It will return the bucket and the key represented by the s3 path
378378
"""
379379

380-
_S3_ACCESSPOINT_TO_BUCKET_KEY_REGEX = re.compile(
381-
r"^(?P<bucket>arn:(aws).*:s3:[a-z\-0-9]*:[0-9]{12}:accesspoint[:/][^/]+)/?"
382-
r"(?P<key>.*)$"
383-
)
384-
_S3_OUTPOST_TO_BUCKET_KEY_REGEX = re.compile(
385-
r"^(?P<bucket>arn:(aws).*:s3-outposts:[a-z\-0-9]+:[0-9]{12}:outpost[/:]"
386-
r"[a-zA-Z0-9\-]{1,63}[/:](bucket|accesspoint)[/:][a-zA-Z0-9\-]{1,63})[/:]?(?P<key>.*)$"
387-
)
388-
match = _S3_ACCESSPOINT_TO_BUCKET_KEY_REGEX.match(s3_path)
389-
if match:
390-
return match.group("bucket"), match.group("key")
391-
match = _S3_OUTPOST_TO_BUCKET_KEY_REGEX.match(s3_path)
392-
if match:
393-
return match.group("bucket"), match.group("key")
380+
bucket_format_list = [
381+
re.compile(
382+
r"^(?P<bucket>arn:(aws).*:s3:[a-z\-0-9]*:[0-9]{12}:accesspoint[:/][^/]+)/?"
383+
r"(?P<key>.*)$"
384+
),
385+
re.compile(
386+
r"^(?P<bucket>arn:(aws).*:s3-outposts:[a-z\-0-9]+:[0-9]{12}:outpost[/:]"
387+
r"[a-zA-Z0-9\-]{1,63}[/:](bucket|accesspoint)[/:][a-zA-Z0-9\-]{1,63})[/:]?(?P<key>.*)$"
388+
),
389+
re.compile(
390+
r"^(?P<bucket>arn:(aws).*:s3-outposts:[a-z\-0-9]+:[0-9]{12}:outpost[/:]"
391+
r"[a-zA-Z0-9\-]{1,63}[/:]bucket[/:]"
392+
r"[a-zA-Z0-9\-]{1,63})[/:]?(?P<key>.*)$"
393+
),
394+
re.compile(
395+
r"^(?P<bucket>arn:(aws).*:s3-object-lambda:[a-z\-0-9]+:[0-9]{12}:"
396+
r"accesspoint[/:][a-zA-Z0-9\-]{1,63})[/:]?(?P<key>.*)$"
397+
),
398+
]
399+
for bucket_format in bucket_format_list:
400+
match = bucket_format.match(s3_path)
401+
if match:
402+
return match.group("bucket"), match.group("key")
394403
s3_components = s3_path.split("/", 1)
395404
bucket = s3_components[0]
396405
s3_key = ""
@@ -1544,7 +1553,9 @@ async def _chmod(self, path, acl, recursive=False, **kwargs):
15441553
bucket, key, version_id = self.split_path(path)
15451554
if recursive:
15461555
allfiles = await self._find(path, withdirs=False)
1547-
await asyncio.gather(*[self._chmod(p, acl, recursive=False) for p in allfiles])
1556+
await asyncio.gather(
1557+
*[self._chmod(p, acl, recursive=False) for p in allfiles]
1558+
)
15481559
elif key:
15491560
if acl not in key_acls:
15501561
raise ValueError("ACL not in %s", key_acls)

‎s3fs/tests/test_s3fs.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,6 +2433,7 @@ def test_split_path(s3):
24332433
"arn:aws:s3:region:123456789012:accesspoint/my-access-point-name",
24342434
"arn:aws:s3-outposts:region:123456789012:outpost/outpost-id/bucket/my-test-bucket",
24352435
"arn:aws:s3-outposts:region:123456789012:outpost/outpost-id/accesspoint/my-accesspoint-name",
2436+
"arn:aws:s3-object-lambda:region:123456789012:accesspoint/my-lambda-object-name",
24362437
]
24372438
test_key = "my/test/path"
24382439
for test_bucket in buckets:

0 commit comments

Comments
 (0)