
What Actually Happens When You Click a Button in a Serverless AWS Application?
Ever wondered what happens behind the scenes when you click a button in a web application? Explore how Amazon API Gateway, AWS Lambda, and DynamoDB work together to build a serverless application, with a simple real-world example.
What Actually Happens When You Click a Button in a Serverless AWS Application?
Imagine you're using a simple task management application.
You type "Learn AWS Lambda" into a textbox, click Add Task, and within a second, your task appears on the screen.
From your perspective, it's just a button.
But behind that button, several things might be happening: an HTTP request is sent, a backend function executes, data is stored in a database, and a response travels back to your browser.
Now imagine building this entire backend without managing a traditional server.
That's where AWS serverless services become interesting.
In this article, we'll understand how Amazon API Gateway, AWS Lambda, and Amazon DynamoDB work together by building a mental model of a simple task application.
No complicated architecture diagrams. Just a clear explanation of what happens at each step.
1. First, What Does Serverless Actually Mean?
The word "serverless" can be misleading.
It doesn't mean your application runs without servers.
Servers still exist. The difference is that AWS manages much of the underlying infrastructure for you.
With a traditional backend, you may need to think about:
- Provisioning servers
- Operating system updates
- Server maintenance
- Scaling infrastructure
- Managing runtime environments
With serverless services, AWS handles much of this infrastructure management.
You can focus more on writing application logic.
For example, AWS Lambda lets you execute code in response to events without managing a server yourself.
But Lambda alone isn't the complete application. We need a way for users to communicate with it and a way to store data.
Let's connect the pieces.
2. Meet the Three AWS Services
<escape>### Amazon API Gateway</escape>
<escape>API Gateway</escape> acts as the entry point for HTTP requests.
When your frontend sends a request, API Gateway receives it and routes it to the appropriate backend integration.
Think of it as the reception desk of your application.
AWS Lambda
Lambda executes your backend code.
For our task application, the Lambda function might:
- Read the incoming task name
- Validate the input
- Save the task
- Return a response
You write the function. AWS manages the infrastructure needed to run it.
Amazon DynamoDB
DynamoDB is a managed NoSQL database.
It stores our tasks so they don't disappear when the user refreshes the page.
For example, a task item could look like this:
{ "taskId": "task-101", "taskName": "Learn AWS Lambda", "completed": false}Each service has a different responsibility.
AWS Service | Responsibility |
|---|---|
API Gateway | Receives HTTP requests |
Lambda | Executes backend logic |
DynamoDB | Stores application data |
This separation makes the application easier to understand and maintain.
3. Let's Follow a Single Button Click
Here is the architecture:
USER | | Clicks "Add Task" v REACT FRONTEND | | HTTP POST Request v AMAZON API GATEWAY | | Invokes Function v AWS LAMBDA | | Saves Task v AMAZON DYNAMODB | | Returns Data v AWS LAMBDA | | HTTP Response v AMAZON API GATEWAY | v REACT FRONTEND | v TASK DISPLAYEDNow let's understand each step.
Step 1: The frontend sends a request
Suppose the user enters:
"Learn AWS"
The React frontend sends an HTTP POST request.
Conceptually, it could look like this:
const response = await fetch( "https://your-api.example.com/tasks", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ taskName: "Learn AWS" }) });The frontend is not directly inserting data into DynamoDB.
It is asking the backend to perform the operation.
Step 2: API Gateway receives the request
API Gateway receives the HTTP request.
It identifies the configured route and invokes the connected Lambda function.
For example:
POST /tasksThis route could be connected to a Lambda function named:
CreateTaskFunctionAPI Gateway provides the interface between the frontend and the backend.
Step 3: Lambda executes the application logic
Now our Lambda function starts processing the request.
A simplified Node.js example:
export const handler = async (event) => { const body = JSON.parse(event.body || "{}");
if (!body.taskName) { return { statusCode: 400, body: JSON.stringify({ message: "Task name is required" }) }; }
// Save the task to DynamoDB here.
return { statusCode: 201, body: JSON.stringify({ message: "Task created successfully" }) };};Notice something important.
Lambda is not just executing code. It is also handling application logic, such as validating input and deciding what response to return.
This is why backend logic should not simply be placed everywhere in the frontend.
Step 4: Lambda communicates with DynamoDB
After validation, Lambda uses the AWS SDK to store the task.
In a real implementation, the Lambda function would use a DynamoDB operation such as
PutItem or PutCommand .The data becomes persistent.
This means the task can still exist when the user closes and reopens the application.
Step 5: The response returns to the frontend
Once the operation succeeds, Lambda returns a response.
API Gateway passes that response back to the frontend.
React can then update the UI.
The user sees:
My Tasks
✓ Learn AWSThat's the entire journey of a single button click.
A simple UI interaction can involve multiple cloud services working together.
4. Why Is This Architecture Called Serverless?
The application still has a backend.
However, we don't need to manually provision and maintain a virtual machine to execute our backend code.
Lambda runs code in response to requests.
DynamoDB handles database infrastructure.
API Gateway handles API entry and routing.
AWS manages much of the infrastructure behind these services.
This can be useful for:
- Small web applications
- APIs
- Event-driven applications
- Automation workflows
- Prototypes and MVPs
However, serverless doesn't automatically mean cheaper or better.
Applications with predictable, continuous workloads may benefit from other architectures.
Choosing the right architecture depends on the workload.
5. What Happens If Something Goes Wrong?
This is where understanding the architecture becomes useful.
Suppose your task isn't appearing on the screen.
Where would you look?
Case 1: API Gateway returns an error
Check whether the API route exists and whether the integration is configured correctly.
Also inspect the response status code.
Case 2: Lambda executes but fails
Open Amazon CloudWatch Logs.
Lambda can send execution logs to CloudWatch, helping you inspect errors and understand what happened during an invocation.
For example, you might find:
AccessDeniedException:User is not authorized to performdynamodb:PutItemThis indicates a permissions problem.
Case 3: Lambda cannot write to DynamoDB
The Lambda execution role may not have the required DynamoDB permissions.
For example, it may need permission to perform
dynamodb:PutItem on the specific table.Giving the function full access to every DynamoDB table is unnecessary.
This is another example of the least-privilege principle.
Case 4: The frontend cannot call the API
Check the API URL, browser network tab, and CORS configuration.
Sometimes the backend is working correctly, but the browser is blocking the request because the API doesn't allow the frontend's origin.
Understanding the flow helps you troubleshoot systematically instead of randomly changing settings.
6. What I Would Build as a Beginner
If you're learning AWS, I wouldn't start with a complicated production application.
I'd start with a small task manager.
<escape>### Features</escape>
- Create a task
- View all tasks
- Mark a task as completed
- Delete a task
<escape>### Architecture</escape>
- Frontend: React
- API: Amazon API Gateway
- Backend: AWS Lambda with Node.js
- Database: Amazon DynamoDB
- Logging: Amazon CloudWatch
- Permissions: AWS IAM
Start with one API endpoint.
Make it work.
Then add the next endpoint.
This approach helps you understand the purpose of each service rather than just following a tutorial and copying code.
Remember to configure authentication and authorization before exposing a real application to users. Also, review AWS pricing and clean up resources after experimenting.
Final Thoughts
The interesting part of serverless architecture isn't that AWS removes servers.
It's that we can break an application into smaller responsibilities and let managed services handle much of the infrastructure.
A button click becomes an HTTP request.
An HTTP request reaches API Gateway.
API Gateway invokes Lambda.
Lambda processes the request and communicates with DynamoDB.
The result travels back to the frontend.
Once you understand this flow, AWS services stop feeling like a collection of unrelated names.
They start making sense as building blocks.
If you're learning AWS, try building this small task application yourself. You'll learn much more by tracing one request from the browser to the database than by memorizing service definitions.
One question for fellow developers:
When learning cloud development, do you prefer starting with a small application like this, or do you jump straight into building a complete project?
I'd love to hear your approach.
Official AWS Documentation
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article