【问题标题】:download svs file on s3 directly to RAM in AWS Lambda or open without local download将 s3 上的 svs 文件直接下载到 AWS Lambda 中的 RAM 或无需本地下载即可打开
【发布时间】:2019-12-05 15:58:04
【问题描述】:

我想使用 AWS Lambda (Python) 进行图像 (svs) 预处理(创建图块等)。不幸的是,图像大约 1 GB,不适合 /tmp (512MB)。因此,我希望通过以下方式将图像直接加载到 RAM 中:

s3_response_object = s3_client.get_object(Bucket=bucket, Key=key)
object_content = s3_response_object['Body'].read()
inmemoryfile = io.BytesIO(object_content)
Image.open(inmemoryfile)

或者直接下载图片到ramfs或者类似的东西:

from memory_tempfile import MemoryTempfile 
import memory_tempfile

在 svs 文件中也只需要 10 个级别中的 1 个。因此,如果有一种方法只能从 s3 存储桶中读取文件中的特定信息,那就太好了。

谢谢

【问题讨论】:

  • 您尝试过这些选项吗?发生了什么?关于在 S3 中读取对象的特定部分的问题,是的,只要您知道所需部分的偏移量和长度,您就可以使用范围获取来执行此操作(您可能需要先从文件本身)。

标签: python amazon-web-services amazon-s3 aws-lambda image-preprocessing


【解决方案1】:

我推荐 s3fs https://github.com/dask/s3fs

import s3fs
fs = s3fs.S3FileSystem()

# You don't need "s3://" in your path if you don't want it
with fs.open('s3://file/path') as fh:
    do_stuff(fh)

【讨论】:

  • s3fs 将是一个不错的选择,但不幸的是不在 AWS Lambda 中,因为它基于 FUSE :/
猜你喜欢
  • 2019-01-20
  • 1970-01-01
  • 1970-01-01
  • 2020-12-28
  • 2021-11-22
  • 2019-06-22
  • 2017-05-25
  • 1970-01-01
  • 2021-04-19
相关资源
最近更新 更多