---
title: "Discussion on \"On-the-fly image resizing with AWS Lambda, S3 & CloudFront\" | Hashnode"
description: "Discussion on \"On-the-fly image resizing with AWS Lambda, S3 & CloudFront\". How to lazily process 300k images and avoid the time-consuming and costly batch processing of every single asset."
url: "https://hashnode.com/posts/on-the-fly-image-resizing-with-aws-lambda-s3-and-cloudfront/61124f7efab8db0c4fc31a42"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [On-the-fly image resizing with AWS Lambda, S3 & CloudFront](https://blog.stefanolaru.com/on-the-fly-image-resizing-with-aws-lambda-s3-and-cloudfront?utm_source=hashnode&utm_medium=feed)

How to lazily process 300k images and avoid the time-consuming and costly batch processing of every single asset.

Aug 10, 2021 · 8 min read · blog.stefanolaru.com  
Read the article

-   [#aws](https://hashnode.com/tag/aws)
-   [#aws-lambda](https://hashnode.com/tag/aws-lambda)
-   [#image-processing](https://hashnode.com/tag/image-processing)
-   [#serverless](https://hashnode.com/tag/serverless)
-   [#tutorial](https://hashnode.com/tag/tutorial)

## Written by

[Stefan Olaru](https://hashnode.com/@stefanolaru)

@stefanolaru

  
[View profile](https://hashnode.com/@stefanolaru)

Head of Development | Architect | 7x AWS Certified | AWS Community Builder | Serverless

An architect by trade, practicing architecture in the Cloud. 7x AWS Certified, AWS Community Builder, Serverless advocate, Vue enthusiast.

## Responses 2

Markdown supported · ⌘↵ to post

[Sameet](https://hashnode.com/@Sameet93)

[Nov 25, 2022](https://hashnode.com/posts/on-the-fly-image-resizing-with-aws-lambda-s3-and-cloudfront/61124f7efab8db0c4fc31a42/comment/63809f90e806cdee4ae93ffe)

Hi Stefan,

How could you change this to also change the images into a different format?

Thanks

[Stefan Olaru](https://hashnode.com/@stefanolaru)

[Nov 29, 2022](https://hashnode.com/posts/on-the-fly-image-resizing-with-aws-lambda-s3-and-cloudfront/61124f7efab8db0c4fc31a42/comment/63809f90e806cdee4ae93ffe#reply-6385e99d7faf6e3605f691a5)

Hi Sameet,

You'll have to tweak the code a bit, have a look at Sharp's output options: [sharp.pixelplumbing.com/api-output](https://sharp.pixelplumbing.com/api-output)

[DK](https://hashnode.com/@kakallatt)

[Feb 22, 2022](https://hashnode.com/posts/on-the-fly-image-resizing-with-aws-lambda-s3-and-cloudfront/61124f7efab8db0c4fc31a42/comment/62148a5695c64c6eda455e36)

Hi Stefan,

I followed your instruction but when I visited the URL to resize image, it just showed AccessDenied. The URL for the original image still works.

[DK](https://hashnode.com/@kakallatt)

[Feb 22, 2022](https://hashnode.com/posts/on-the-fly-image-resizing-with-aws-lambda-s3-and-cloudfront/61124f7efab8db0c4fc31a42/comment/62148a5695c64c6eda455e36#reply-621531461543b38e7605cc18)

[Stefan Olaru](https://hashnode.com/@stefanolaru)

Thank you for the quick reply. I got a new error:

`darwin-x64' binaries cannot be used on the 'linux-x64' platform. Please remove the 'node_modules/sharp' directory and run 'npm install' on the 'linux-x64' platform.`

Do you know how to fix it?

[Richathon](https://hashnode.com/@zozoname)

[Feb 26, 2022](https://hashnode.com/posts/on-the-fly-image-resizing-with-aws-lambda-s3-and-cloudfront/61124f7efab8db0c4fc31a42/comment/62148a5695c64c6eda455e36#reply-621a06f745bf7fc41cc9ba04)

[DK](https://hashnode.com/@kakallatt)

Please refer this one: [github.com/lovell/sharp/issues/2443](https://github.com/lovell/sharp/issues/2443)

The error message suggests node\_modules was populated by running npm install on macOS/Darwin, which won't work on Linux. Make sure you're not sharing or copying an external node\_modules within the Linux container.

\=> It means that we should delete node\_modules and run npm install in linux os not macos

[DK](https://hashnode.com/@kakallatt)

[Mar 21, 2022](https://hashnode.com/posts/on-the-fly-image-resizing-with-aws-lambda-s3-and-cloudfront/61124f7efab8db0c4fc31a42/comment/62148a5695c64c6eda455e36#reply-6238df3f6622115cc80487c5)

[Richathon](https://hashnode.com/@zozoname) Thank you for your reply. So I need a machine running Linux to re-compile the script to make the Lamda function work? I am using macOS right now, but I didn't run npm install. I just downloaded the zip file and upload it to Lamda.
