使用libvips旋转图片时出现「设备上没有剩余空间」错误求助
Let's break down why you're hitting this error, even with a 10MB JPG and 512MB of temp storage:
Libvips uses disk caching for image operations by default, and even though your source image is small, the rotation process might generate intermediate temporary files that eat into Lambda's limited /tmp space (keep in mind Lambda's OS and runtime already take up some of that 512MB). The wbuffer_write: write failed error confirms libvips is trying to write to disk but can't find enough free space.
Here are the most straightforward fixes, ordered by ease of implementation:
1. Force libvips to use in-memory caching
The quickest fix is to set the VIPS_DISC_THRESHOLD environment variable to a value larger than the memory needed for your rotation. This tells libvips to keep all processing in RAM instead of writing temp files to disk.
Modify your command like this:
VIPS_DISC_THRESHOLD=100000000 vips rot original.jpg rotated.jpg d90
We're setting the threshold to 100MB (100,000,000 bytes) — way more than enough for a 10MB JPG rotation. Libvips will stick to memory entirely, avoiding any /tmp writes.
2. Verify available /tmp space (for debugging)
If you want to confirm how much space is actually free before running your command, add a quick check:
df -h /tmp
This will show you the used/free space in /tmp. Sometimes Lambda's runtime or pre-installed packages take up more space than expected, which helps explain why even a small temp file can trigger the error.
3. Increase Lambda's temporary storage (if needed)
If adjusting the cache threshold doesn't work (unlikely for your 10MB image), you can bump up Lambda's temp storage beyond 512MB. AWS now allows up to 10GB of ephemeral storage for Lambda functions — just update your function's configuration to allocate more space to /tmp.
That said, the first fix should resolve your issue without needing to increase storage.
内容的提问来源于stack exchange,提问作者Vikram Singh Shekhawat

