Skip to content

Add image optimization Lambda for /_next/image requests #8

@aynaash

Description

@aynaash

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

  1. Image optimization Lambda — Node.js function with Sharp compiled for arm64
  2. CloudFront behavior — Route /_next/image* to the image Lambda
  3. 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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesthelp wantedExtra attention is needed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions