Skip to content

Commit

Permalink
add support for requester pays buckets (#66)
Browse files Browse the repository at this point in the history
* add support for requester pays buckets

* update readme
  • Loading branch information
geospatial-jeff authored Aug 20, 2020
1 parent 40730c3 commit bc22bce
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ Configuration options are exposed through environment variables:
- **BOUNDLESS_READ_FILL_VALUE** - determines the value used to fill boundless reads (defaults to 0)
- **LOG_LEVEL** - determines the log level used by the package (defaults to ERROR)
- **VERBOSE_LOGS** - enables verbose logging, designed for use when `LOG_LEVEL=DEBUG` (defaults to FALSE)
- **AWS_REQUEST_PAYER** - set to `requester` to enable reading from S3 RequesterPays buckets.

Refer to [`aiocogeo/config.py`](https://github.com/geospatial-jeff/aiocogeo/blob/master/aiocogeo/config.py) for more details about configuration options.

Expand Down
5 changes: 5 additions & 0 deletions aiocogeo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@

# Determines the fill value used for boundless reads
BOUNDLESS_READ_FILL_VALUE: int = int(os.getenv("BOUNDLESS_READ_FILL_VALUE", "0"))

# Enable reading from a S3 requester pays bucket
AWS_REQUEST_PAYER: str = os.getenv(
"AWS_REQUEST_PAYER", None
)
5 changes: 4 additions & 1 deletion aiocogeo/filesystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,12 @@ async def __aenter__(self):
class S3Filesystem(Filesystem):

async def _range_request(self, start: int, offset: int) -> bytes:
kwargs = {}
if config.AWS_REQUEST_PAYER:
kwargs['RequestPayer'] = config.AWS_REQUEST_PAYER
begin = time.time()
try:
req = await self.object.get(Range=f'bytes={start}-{start+offset}')
req = await self.object.get(Range=f'bytes={start}-{start+offset}', **kwargs)
except botocore.exceptions.ClientError as e:
await self._close()
raise FileNotFoundError(f"File not found: {self.filepath}") from e
Expand Down
6 changes: 5 additions & 1 deletion aiocogeo/scripts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ def _make_bold(s, **kwargs):
def _get_ifd_stats(ifds):
ifd_stats = []
for idx, ifd in enumerate(ifds):
tile_sizes = [b / 1000 for b in ifd.TileByteCounts.value]
if not isinstance(ifd.TileByteCounts.value, tuple):
byte_counts = [ifd.TileByteCounts.value]
else:
byte_counts = ifd.TileByteCounts.value
tile_sizes = [b / 1000 for b in byte_counts]
mean_tile_size = round(sum(tile_sizes) / len(tile_sizes), 3)
ifd_stats.append({
'id': idx,
Expand Down

0 comments on commit bc22bce

Please sign in to comment.