Deployment Overview
We’ll do this in steps:
- Package your code
- Create a Lambda function
- Upload the code
- Create an API Gateway
- Connect them
- Test the URL
Let’s go.
Step 1: Package Your Code
Lambda needs your code in a zip file. Create the zip:
zip -r function.zip lambda-handler.js
Note: If you used Express with aws-serverless-express, include node_modules:
zip -r function.zip lambda-handler.js node_modules/
But for our simple handler, we don’t need any dependencies, so just the handler file is enough.
Step 2: Choose a Region
Log into AWS Console and pick a region. We’ll use us-east-1 (N. Virginia) in examples, but pick one close to you.
Why regions matter: Lower latency for your users, and some services are region-specific.
Step 3: Create Lambda Function
- Go to AWS Console → Lambda
- Click “Create function”
- Choose “Author from scratch”
- Fill in:
- Function name:
notes-api - Runtime: Node.js 18.x (or latest)
- Architecture: x86_64
- Function name:
- Click “Create function”
You’ll see the function configuration page.
Step 4: Upload Your Code
- Scroll to “Code source”
- Click “Upload from” → “.zip file”
- Select your
function.zipfile - Click “Save”
AWS will upload and extract your code.
Step 5: Set the Handler
The handler tells Lambda which function to call.
- In “Code source”, find “Runtime settings”
- Click “Edit”
- Set Handler to:
lambda-handler.handler- This means: file is
lambda-handler.js, function ishandler
- This means: file is
- Click “Save”
Step 6: Test Lambda (Optional but Recommended)
Before connecting to API Gateway, test Lambda directly:
- Click “Test” tab
- Click “Create new test event”
- Name it “test-get-notes”
- Use this JSON:
{
"path": "/notes",
"httpMethod": "GET",
"headers": {},
"body": null
}
- Click “Save”
- Click “Test”
You should see:
- Status: “Succeeded”
- Response: Your notes JSON
If you see an error, check:
- Handler name is correct
- Code uploaded successfully
- JSON syntax is valid
Step 7: Create API Gateway
Now create the HTTP endpoint:
- Go to AWS Console → API Gateway
- Click “Create API”
- Choose “HTTP API” (not REST API - HTTP is simpler)
- Click “Add integration”
- Select:
- Integration type: Lambda
- Lambda function:
notes-api(the one you created)
- Click “Next”
- Configure routes:
- Method: GET
- Resource path:
/notes - Click “Add another route”
- Method: GET
- Resource path:
/health - Click “Add another route”
- Method: POST
- Resource path:
/notes
- Click “Next”
- Review and click “Create”
Step 8: Deploy the API
- You’ll see your API dashboard
- Click “Deploy”
- Choose stage:
prod(or create a new one) - Click “Deploy”
You’ll get a URL like:
https://abc123xyz.execute-api.us-east-1.amazonaws.com
This is your API endpoint!
Step 9: Test the Real URL
Open a terminal and test:
curl https://abc123xyz.execute-api.us-east-1.amazonaws.com/health
You should see:
{"status":"ok","timestamp":"2025-12-02T10:00:00.000Z"}
Test notes:
curl https://abc123xyz.execute-api.us-east-1.amazonaws.com/notes
Test POST:
curl -X POST https://abc123xyz.execute-api.us-east-1.amazonaws.com/notes \
-H "Content-Type: application/json" \
-d '{"text":"Test from cloud"}'
It works! Your API is live on the internet.
Understanding IAM
What is IAM? Identity and Access Management. It’s how AWS says “who can do what.”
For Lambda:
- Lambda needs permission to run (it gets this automatically)
- API Gateway needs permission to call Lambda (we set this up when creating the integration)
Least privilege: Give only the permissions needed. For this tutorial, the defaults are fine.
You don’t need to configure IAM manually - API Gateway sets it up when you create the integration.
Understanding Cold Starts
What is a cold start? The first request after inactivity can be slow (1-3 seconds). Lambda needs to start the function.
Why it happens: Lambda stops your function when not used. Starting it takes time.
How to reduce:
- Use Provisioned Concurrency (costs money)
- Keep functions warm with scheduled pings
- For most APIs, cold starts are fine (users don’t notice 1-2 seconds)
For this tutorial: Don’t worry about it. Your API will work fine.
Request Flow Visualization
Troubleshooting
“Internal server error” (500):
- Check Lambda logs (CloudWatch)
- Verify handler name is correct
- Check code for syntax errors
“Resource not found” (404):
- Check route path matches (
/notesnot/note) - Verify API Gateway is deployed
- Check stage name in URL
“Timeout”:
- Lambda has a default 3-second timeout
- Increase it in Lambda settings if needed
- Check if code has infinite loops
“Permission denied”:
- API Gateway needs permission to invoke Lambda
- Re-check the integration settings
Key Takeaways
Before moving on:
- Package code as zip - Lambda needs code packaged
- Handler name matters -
filename.functionName - API Gateway creates the URL - It’s your public endpoint
- Test before deploying - Use Lambda test events first
- IAM handles permissions - Usually automatic, but good to understand
What’s Next?
In the next page, we’ll add environment variables, check logs, and learn basic troubleshooting. This helps you debug issues in production.