aws-samples / aws-samples/amazon-textract-textractor

S3 path parsing for textractcaller is not robust enough

Open
#345 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
493
Forks
163
PR merge metrics
No merged PRs in 30d

Description

This line (and several others similar to this in the same file)

https://github.com/aws-samples/amazon-textract-textractor/blob/7f16fa74a6ab2f5b1a322c4c5c915266361deecf/caller/textractcaller/t_call.py#L579

Could potentially break s3 path's like

```
s3://bucket-name/path/to/s3://another/path/to/file.pdf
```

Yes this is apparently valid, and S3 has no issues with this, there are "some" services that create object keys like this and trying textractcaller, either via Textractor or directly causes the following error.

```
RegionMismatchError: Region passed in the profile_name and S3 bucket do not match. Ensure the regions are the same.
```

A slightly more robust alternative is something like below.

```python
def parse_s3_url(url: str):
if url.lower().startswith("s3://"):
url_parts = url[5:].split("/", 1)
bucket = url_parts[0]
key = url_parts[1] if len(url_parts) > 1 else None
return bucket, key
else:
raise ValueError("URL must be in s3://bucket/key format")
```

Will do a PR.

Contributor guide

Open the contributing guide

Research direction

Start in caller/textractcaller/t_call.py at line 579 and inspect the other similar S3 path parsing locations in that file. Trace how an S3 URL containing a later s3:// segment is split and verify the behavior using the issue's example. Done means valid nested S3 object keys no longer trigger the reported RegionMismatchError.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python
Domain
backend, cloud
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.