Summary
Next.js <Image> component requests images via /_next/image?url=...&w=...&q=.... Currently these requests hit the server Lambda with no optimization. We need a dedicated image optimization Lambda.
Required Components
- Image optimization Lambda — Node.js function with Sharp compiled for arm64
- CloudFront behavior — Route
/_next/image* to the image Lambda
- S3 integration — Fetch source images from the assets S3 bucket
Flow
CloudFront → /_next/image?url=/photo.jpg&w=640&q=75
→ Image Lambda
→ Fetch original from S3
→ Resize with Sharp (width=640, quality=75)
→ Convert to WebP/AVIF
→ Return with Cache-Control headers
Infrastructure to Auto-Provision
- New Lambda function (
<app>-image-optimizer)
- CloudFront cache behavior for
/_next/image*
- IAM permissions for image Lambda to read from S3
References
Difficulty: Hard · Language: Go + JavaScript
Summary
Next.js
<Image>component requests images via/_next/image?url=...&w=...&q=.... Currently these requests hit the server Lambda with no optimization. We need a dedicated image optimization Lambda.Required Components
/_next/image*to the image LambdaFlow
Infrastructure to Auto-Provision
<app>-image-optimizer)/_next/image*References
Difficulty: Hard · Language: Go + JavaScript