By Cloud Engineering Team

Deploying a Simple API on AWS - Deploy to AWS

Intermediate 8 min
Cloud ComputingAWS LambdaAPI GatewayDeployment

Deployment Overview

We’ll do this in steps:

  1. Package your code
  2. Create a Lambda function
  3. Upload the code
  4. Create an API Gateway
  5. Connect them
  6. 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

  1. Go to AWS Console → Lambda
  2. Click “Create function”
  3. Choose “Author from scratch”
  4. Fill in:
    • Function name: notes-api
    • Runtime: Node.js 18.x (or latest)
    • Architecture: x86_64
  5. Click “Create function”

You’ll see the function configuration page.

Step 4: Upload Your Code

  1. Scroll to “Code source”
  2. Click “Upload from” → “.zip file”
  3. Select your function.zip file
  4. Click “Save”

AWS will upload and extract your code.

Step 5: Set the Handler

The handler tells Lambda which function to call.

  1. In “Code source”, find “Runtime settings”
  2. Click “Edit”
  3. Set Handler to: lambda-handler.handler
    • This means: file is lambda-handler.js, function is handler
  4. Click “Save”

Before connecting to API Gateway, test Lambda directly:

  1. Click “Test” tab
  2. Click “Create new test event”
  3. Name it “test-get-notes”
  4. Use this JSON:
{
  "path": "/notes",
  "httpMethod": "GET",
  "headers": {},
  "body": null
}
  1. Click “Save”
  2. 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:

  1. Go to AWS Console → API Gateway
  2. Click “Create API”
  3. Choose “HTTP API” (not REST API - HTTP is simpler)
  4. Click “Add integration”
  5. Select:
    • Integration type: Lambda
    • Lambda function: notes-api (the one you created)
  6. Click “Next”
  7. 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
  8. Click “Next”
  9. Review and click “Create”

Step 8: Deploy the API

  1. You’ll see your API dashboard
  2. Click “Deploy”
  3. Choose stage: prod (or create a new one)
  4. 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

HTTP Invoke Execute Return Response HTTP Internet API Gateway Lambda Your Code Response

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 (/notes not /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:

  1. Package code as zip - Lambda needs code packaged
  2. Handler name matters - filename.functionName
  3. API Gateway creates the URL - It’s your public endpoint
  4. Test before deploying - Use Lambda test events first
  5. 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.

Discussion

Join the conversation and share your thoughts

Discussion

0 / 5000