简体   繁体   English

设备上没有剩余空间 - AWS Lambda + Sharp

[英]No space left on device - AWS Lambda + Sharp

I am trying to convert SVG to TIFF using sharp.我正在尝试使用 sharp 将 SVG 转换为 TIFF。 My NodeJs application is deployed on AWS Lambda. As the AWS Lambda /tmp directory can have maximum size of 512 MB, for the large files I am getting error "No space left on device".我的 NodeJs 应用程序部署在 AWS Lambda 上。由于 AWS Lambda /tmp 目录的最大大小为 512 MB,对于大文件,我收到错误“设备上没有剩余空间”。

I tried to search inte.net but could not find any good solution.我试图搜索 inte.net 但找不到任何好的解决方案。

Can you please suggest, if it is possible to use sharp on application deployed on AWS Lambda to process large files?你能建议一下,是否可以在部署在 AWS Lambda 上的应用程序上使用 sharp 来处理大文件? If yes the how?如果是的话怎么办?

Otherwise, if you can suggest any alternate way to achieve it on AWS - May be using some other services?否则,如果您可以建议在 AWS 上实现它的任何替代方法 - 可能正在使用其他一些服务?

As far as I can tell you have three options:据我所知,您有以下三种选择:

  1. Mount a EFS volume to your Lambda将 EFS 卷挂载到您的 Lambda
  2. Do stream processing做stream处理
  3. Store the converted image in memory将转换后的图像存储在 memory

Option #1选项1

Mounting an EFS volume to your Lambda instance is effectively like adding a hard drive to your Lambda. But be aware, that the disk is shared between instances of your Lambda and persists after your Lambda is shutdown.将 EFS 卷安装到您的 Lambda 实例实际上就像将硬盘驱动器添加到您的 Lambda。但请注意,该磁盘在您的 Lambda 实例之间共享,并且在您的 Lambda 关闭后仍然存在。

Documentation: https://aws.amazon.com/blogs/compute/using-amazon-efs-for-aws-lambda-in-your-serverless-applications/文档: https://aws.amazon.com/blogs/compute/using-amazon-efs-for-aws-lambda-in-your-serverless-applications/

Option #2选项 #2

This is the more complicated option and might not work with all formats.这是更复杂的选项,可能不适用于所有格式。 But instead of writing every bit to disk, you can process the image in chunks and then write those chunks to S3 for example.但是,您可以分块处理图像,然后将这些块写入 S3,而不是将每一位都写入磁盘。 This way your Lambda does not need to store any data on disk at all and does not need a lot of memory because you are processing the image in small chunks.这样你的 Lambda 根本不需要在磁盘上存储任何数据,也不需要很多 memory 因为你正在以小块的形式处理图像。

Option #3选项 #3

Instead of writing the image to disk ( toFile() ) you could write the result into a buffer ( toBuffer() ).您可以将结果写入缓冲区 ( toBuffer() ),而不是将图像写入磁盘 ( toFile() ())。 Then you use this buffer to write the result to S3 for example.然后您使用此缓冲区将结果写入 S3,例如。 This way no bits touch the disk and your only constrain is the maximum Lambda memory of 10.240 MB.这样就没有位接触磁盘,您唯一的限制是最大 Lambda memory 为 10.240 MB。


Recommendation : Before you try any solution, make sure that you are deleting your converted images.建议:在尝试任何解决方案之前,请确保您要删除转换后的图像。 The /tmp directory persists between requests for as long as your Lambda instance is alive.只要您的 Lambda 实例处于活动状态, /tmp目录就会在请求之间持续存在。 That means that the same Lambda instance could be invoked 20 times and write a new file to /tmp every time.这意味着同一个 Lambda 实例可以被调用 20 次并且每次都将一个新文件写入/tmp If you do not clean up those files after processing them, your "No disk space left" error might be due to old files that not have been deleted.如果您在处理完这些文件后没有清理它们,您的“没有剩余磁盘空间”错误可能是由于未删除的旧文件造成的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 OSError:[Errno 28] 设备上没有剩余空间 - AWS Lambda + Zappa - OSError: [Errno 28] No space left on device - AWS Lambda + Zappa "errorMessage": "[Errno 28] 设备上没有剩余空间" AWS-Lambda - "errorMessage": "[Errno 28] No space left on device" AWS-Lambda OSError 后 AWS Airflow 无法操作:[Errno 28] 设备上没有剩余空间 - AWS Airflow inoperable after OSError: [Errno 28] No space left on device 如何克服 AWS Glue 作业中的 Spark“设备上没有剩余空间”错误 - How to overcome Spark "No Space left on the device" error in AWS Glue Job 在 aws Lambda 上安装 \"sharp\" 时出错 - Something went wrong installing the \"sharp\" on aws Lambda 使用 Sharp 库运行 AWS Lambda 函数时出现问题 - Problem running AWS Lambda function with Sharp library 在 AWS beanstalk 上部署多容器 docker 应用程序时如何防止错误“设备上没有剩余空间”? - how to prevent error "no space left on device" when deploying multi container docker application on AWS beanstalk? 设备上没有剩余空间 [Amazon SageMaker] - No space left on device [Amazon SageMaker] 有没有办法更改 AWS lambda function 的“暂存”(/tmp) 空间位置? - Is there a way to change the 'scratch' (/tmp) space location of an AWS lambda function? 在 AWS Lambda function 中运行 Sharp 时出错:darwin-x64' 二进制文件不能在 'linux-x64' 平台上使用 - Error running Sharp inside AWS Lambda function: darwin-x64' binaries cannot be used on the 'linux-x64' platform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM