
Weekend Showcase Challenge: Tip Jar Calculator
I decided to tackle a very common, everyday friction point—splitting the bill at a restaurant—by building a lightweight, serverless cloud application.
The core vision behind the Tip Jar Calculator is to eliminate the awkward mental math that happens at the end of a group dinner. Users simply enter a bill amount, a tip percentage, and their party size to instantly compute the tip, the total, and the per-person split.
By offloading the computation to the cloud, the application ensures that the client-side remains incredibly lightweight. The
index.html frontend makes a network call to GET /tip?bill=<n>&tip=<pct>&people=<n> and subsequently displays the returned mathematical values. It solves the basic problem of dividing a restaurant check while demonstrating how to build a fully decoupled, serverless web application.How I Built It
Building this project required a careful split between front-end UI design and back-end logic.
On the front end, I wanted a fun, retro aesthetic.
- I styled the interface using warm colors like
#e8863dfor the background and#fce9c8for the main calculator panel.
- To give it some character, I imported the Google Fonts "Righteous" and "Rubik".
- The background utilizes a repeating linear gradient to create a subtle patterned effect.
- I added a prominent button that reads "Groovy, calculate!" which triggers the JavaScript function when clicked.
The back end is powered by a Python script, named
lambda.py . I designed the function to be robust and handle edge cases gracefully.- The script extracts the
bill,tip, andpeoplevalues from the query string parameters, defaulting to 0 for amounts and 1 for the party size if they are missing.
- It includes a
try/exceptblock that catchesTypeErrorandValueError, returning a 400 status code with an error message if the user inputs non-numeric data.
- To prevent division by zero, the script explicitly ensures the
peoplecount is at least 1.
- The mathematical logic computes tip_amount by multiplying the bill by the tip percentage divided by 100, then adds it to the bill for the total, and divides by the party size to find the per_person amount—rounding everything to two decimal places.
- Finally, it returns a 200 status code alongside a JSON payload containing the computed values.
To connect the two, the front end relies on a config.js file. This file initializes a window.API_BASE_URL variable. The frontend JavaScript utilizes the Fetch API to call the cloud endpoint and dynamically updates the DOM with the results, or displays an error message if the API request fails or is not deployed.
AWS Architecture Overview
The backend relies entirely on a serverless architecture provided by Amazon Web Services.
- AWS Lambda - computes tip, total, and per-person amounts.
- API Gateway (HTTP API) - exposes the function over HTTP.
- Amazon S3 - hosts the page (optional; you can also open it locally).
The architectural flow is straightforward: A user interacts with the HTML page, which sends a GET request to the API Gateway. The API Gateway routes the request to the Python Lambda function, which runs the computation and returns the JSON payload back through the gateway to the client. For example, calling the API with
GET /tip?bill=100&tip=15&people=2 returns 200 { "tip": 15.0, "total": 115.0, "per_person": 57.5 } .The infrastructure was deployed entirely via the AWS CLI. I used environment variables to set the region to
us-east-1 and the function name to tip-calculator . The deployment process involves creating an IAM execution role, attaching the AWSLambdaBasicExecutionRole policy, packaging the Python script into a .zip file, and creating the Lambda using the python3.12 runtime. After setting up the HTTP API, I configured CORS to allow all origins and granted the API Gateway permission to invoke the Lambda function. Finally, the deployment script updates config.js with the live API endpoint and starts a local HTTP server on port 8000. I also included a tear-down script to safely delete the API, Lambda function, and IAM roles when the project is no longer needed.

Diving into cloud infrastructure this summer completely changed how I approach software development. Before this, I usually relied on monolithic servers to handle both my web pages and my backend logic. Building the Tip Jar Calculator taught me the true value of decoupling the frontend from the backend.
I gained significant hands-on experience using the AWS Command Line Interface. Scripting the deployment process—from provisioning IAM roles to creating API Gateway routes—taught me how infrastructure as code operates in the real world. Handling Cross-Origin Resource Sharing (CORS) was initially a hurdle, but configuring the API Gateway to explicitly allow GET and OPTIONS methods from all origins solidified my understanding of web security protocols. Overall, the summer gave me the confidence to treat cloud services as composable building blocks rather than intimidating black boxes.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article