Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Benchmarking AWS Amplify, Lambda, Web Functions, and ECS for Next.js

A hands-on benchmark comparing AWS Amplify, Lambda, Web Functions, and ECS for Next.js, covering latency, cold starts, scaling, and monthly costs.

Benchmarking AWS Amplify, Lambda, Web Functions, and ECS for Next.js

A comprehensive benchmarking study was conducted to compare the performance of AWS Amplify, Lambda, Web Functions, and ECS for a Next.js application. To ensure a fair comparison, the same Next.js app was deployed to these four AWS runtimes in the same account and region. The study measured latency under load, cold starts, CPU speed, real limits, and the monthly bill at four traffic levels.

Notably, both Lambda and ECS utilized the same container image, while the Web Function ran the same files from a .zip file. Additionally, the Amplify Hosting service built the exact same Git commit as the other runtimes.

During the benchmarking, several surprising results emerged. The ECS Fargate task with 0.5 vCPU proved to be the fastest option for light requests, but it failed completely under heavy load, with 29% of page requests returning errors and the overloaded task being replaced twice during testing. Both Lambda, Web Functions, and Amplify maintained consistent latency from 10 to 200 requests per second without any errors.

The Web Functions exhibited the fastest CPU performance and did not have the 6 MB response limit constraint, but they cost about four times more than classic Lambda due to billing for memory even during idle periods. Similarly, Amplify cut off requests at approximately 28 seconds and responses at 6 MB, while classic Lambda behind a Function URL also stopped at 6 MB.

The study revealed several key takeaways:

1. The app built consisted of one app, four runtimes and one DynamoDB table. Amplify Hosting built the app from GitHub and ran server-side code on its managed compute. Lambda (Event Function) ran the container image through the Lambda Web Adapter, exposed with a Function URL. Each execution environment handled one request at a time.

2. Prerequisites and cost included an AWS account and CLI v2 with appropriate credentials. Web Functions required a recent version with the aws lambda-web commands (used 2.40.4), Docker with buildx, Node.js 22, and k6 for load tests. A GitHub account was necessary for Amplify Hosting, and everything was set up in eu-central-1. Lambda and Fargate employed arm64 (Graviton) with 1024 MB of memory for Lambda and 0.5 vCPU and 1 GB for Fargate.

A Web Function environment had a fixed size of 2 arm64 vCPUs and 2 GB, while Amplify chose its own compute.

3. The app and image were a normal Next.js app router project with a standalone output producing a small self-contained server.js for the container. The Dockerfile incorporated the Lambda Web Adapter, Lambda, ECS, and readiness check path for each runtime. The Next.js cache was moved to /tmp to avoid measuring health checks that could influence the measured code. The image was built for arm64 and pushed to ECR, and security fixes were addressed by rebuilding base images on a schedule.

The benchmarking results provide valuable insights into the performance and cost implications of deploying a Next.js application on different AWS runtimes, helping developers make informed decisions based on their specific requirements.

Rewritten by urgent.news; may contain errors — check the original.

Read the original at hackernoon.com →

Report a problem with this story

More in Tech

More from Saturday 21 November →