AWS Builder Center

Building Your First Serverless API with AWS Lambda and API Gateway

A beginner-friendly guide to creating a scalable, serverless REST API using AWS Lambda and Amazon API Gateway. Learn how to deploy your first function, configure HTTP routes, and test your endpoint without managing a single server.

Serverless architecture allows developers to build and run applications without the burden of managing infrastructure. In this guide, we will walk through the basics of creating a simple REST API using AWS Lambda and Amazon API Gateway.

Why Serverless?

  • No infrastructure management: Focus entirely on your code.
  • Auto-scaling: Scales automatically with demand.
  • Pay for value: You only pay for the compute time you consume.

Step 1: Create a Lambda Function

AWS Lambda is the core compute service for serverless applications.
  1. Navigate to the Lambda console.
  2. Click Create function and select Author from scratch.
  3. Name your function hello-world-api and choose a runtime (e.g., Python 3.10 or Node.js 20.x).
  4. Replace the boilerplate code with a simple JSON response and click Deploy.

Step 2: Configure API Gateway

API Gateway acts as the "front door" for your Lambda function.
  1. Go to the API Gateway console and create a new HTTP API.
  2. Add an integration and select your hello-world-api Lambda function.
  3. Configure your routes (e.g., GET /hello) and attach them to the integration.
  4. Leave the default stage settings and click Create.

Step 3: Test Your API

Once your API is created, API Gateway will provide an invoke URL. Copy this URL, append your route (e.g., https://your-api-id.execute-api.region.amazonaws.com/hello), and paste it into your browser. You should see the JSON response returned by your Lambda function!

Conclusion

You've just built a fully functional, highly scalable API in a matter of minutes. From here, you can start integrating DynamoDB for storage or setting up IAM policies for security. Happy building!
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