AWS Builder Center
Weekend Showcase Challenge: Serverless BMI Calculator

Weekend Showcase Challenge: Serverless BMI Calculator

This project is a lightweight, cloud-powered Body Mass Index (BMI) calculator that offloads core logic to the AWS ecosystem. By separating the user interface from the backend mathematical computation, it provides a practical demonstration of how modern serverless web applications are structured and deployed.

In the modern web landscape, application frontends are frequently burdened with heavy processing that is better suited for a secure, scalable backend. The vision for this project was to create a seamless, user-friendly health tool while completely decoupling the interface from the underlying business logic.
The application is a Body Mass Index (BMI) calculator where users simply input their weight in kilograms and height in centimeters. However, instead of the browser computing the results locally, the application relies on an external API. When the user clicks "Calculate," the frontend JavaScript makes a network request to an AWS cloud backend. The backend processes the inputs, applies the standard BMI formula (weight divided by height squared), and evaluates the result against established health thresholds.
Once computed, the user is provided with their exact BMI rounded to one decimal place, along with their health category—whether they are Underweight, Normal, Overweight, or Obese. By shifting the processing to the cloud, the application ensures that the core algorithm remains secure, centrally managed, and easily updatable without requiring any changes to the client-side code.

AWS Services Used

To achieve this decoupled architecture, the project relies on a streamlined combination of three primary Amazon Web Services:
  • Amazon S3: This service is utilized to host the static HTML, CSS, and JavaScript files that make up the user interface. It offers a highly available, low-cost solution for serving static web assets to users globally.
  • AWS Lambda: Acting as the computational brain of the application, a Python-based Lambda function handles the actual BMI math and categorization. Because it is serverless, it only runs when a user submits a calculation, scaling automatically to meet demand.
  • API Gateway (HTTP API): This service acts as the secure front door to the backend, exposing the Lambda function over the internet via HTTP. It routes the incoming  GET  requests from the web page directly to the serverless function.

How I Built It

The build process began with the frontend. I designed a clean, card-based interface using standard HTML and CSS, incorporating the 'Poppins' font from Google Fonts for a modern typographic feel. The design uses a calming teal and white color palette, complete with a gradient calculation button to provide a polished user experience.
One of the key technical decisions was how to link the frontend to the backend dynamically. Hardcoding API URLs into HTML is a bad practice, so I abstracted the API base URL into a separate config.js file. This file initializes a window.API_BASE_URL variable, which is intelligently overwritten at deployment time with the live API Gateway URL. The frontend JavaScript then constructs the final request URI by appending /bmi?weight=<kg>&height=<cm> to this base URL.
For the backend, I chose Python 3.12 as the runtime due to its readability and robust JSON handling. The Lambda function is designed with strict validation: it extracts the query string parameters from the event payload and immediately checks if the weight and height are valid, positive numbers. If the inputs are invalid, the API returns a structured 400 Bad Request error. If valid, it computes the metric and categorizes a BMI under 18.5 as Underweight, up to 25 as Normal, up to 30 as Overweight, and anything higher as Obese.
The primary challenge during development was navigating cloud permissions and cross-origin security. Browsers strictly enforce CORS (Cross-Origin Resource Sharing), so I had to explicitly configure the API Gateway to allow all origins and permit  GET  and  OPTIONS  methods. Additionally, setting up the IAM (Identity and Access Management) roles via the command line required careful attention to detail. I had to provision an execution role with a trust policy for  lambda.amazonaws.com , attach the  AWSLambdaBasicExecutionRole  policy, and explicitly grant API Gateway the permission to invoke the function.

Project App Screenshot



What I Learned

Diving into cloud infrastructure over the summer fundamentally shifted my approach to building software. I learned that "serverless" is less about eliminating servers and more about maximizing developer velocity by offloading infrastructure management to a cloud provider.
Writing the backend logic taught me the nuances of event-driven programming. Instead of setting up a traditional routing framework like Flask or Express, I learned how to directly parse AWS event dictionaries to access HTTP query parameters. I also gained a deep appreciation for API contracts. Defining a clear expectation—such as receiving specific variables and returning a standard 200 status code with a predictable JSON payload like  {"bmi": 22.9, "category": "Normal"} —made integrating the frontend incredibly smooth.
Furthermore, I mastered the basics of Infrastructure as Code and command-line automation. Using the AWS CLI to zip code, provision IAM roles, deploy Lambda functions, and map HTTP APIs taught me how to move away from clicking through a web console to creating repeatable, automated deployments. I also learned the crucial habit of resource teardown; writing the final cleanup scripts to delete APIs, detach policies, and remove roles ensured I maintained a clean and cost-effective cloud environment.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article