04 / 06

Can a Lambda function be triggered by an API Gateway? How?

Difficulty: 4/10
Lambda Proxy Integration, API Gateway Timeouts, Serverless Security

Yes, AWS Lambda can be triggered by Amazon API Gateway. This integration allows you to build RESTful or WebSocket APIs that invoke your Lambda functions in response to HTTP(S) requests. This is a common pattern for creating serverless web applications, backend services, or mobile app APIs.

Steps to Trigger Lambda with API Gateway
  1. 1

    Create or open an existing API in API Gateway (REST or HTTP API)

  2. 2

    Create a new route or resource (e.g., /upload, /login)

  3. 3

    Attach a method (e.g., GET, POST) to the route

  4. 4

    Select 'Lambda Function' as the integration type

  5. 5

    Choose the Lambda function to invoke

  6. 6

    Deploy the API to a stage (e.g., dev, prod)

  7. 7

    Invoke the API endpoint using a browser, Postman, or curl

Sample curl Request to Trigger Lambda via API Gateway

Scenario Questions

0-2 years experience

  1. 1Imagine you're building a simple contact form on a website. When a user submits it, you want to trigger a Lambda function to send an email. How would you set up API Gateway to pass the form data directly to your Lambda, and how does your Lambda access that data?
  2. 2You've connected an API Gateway endpoint to a Lambda function, but when you test it in your browser, you get a CORS error. What do you need to configure in both API Gateway and your Lambda's response to fix this?

2-5 years experience

  1. 1We have a Lambda function behind an API Gateway that processes user uploads. Suddenly, users start getting 502 Bad Gateway errors for larger payloads, even though the Lambda logs show a 200 OK and execution completed successfully. What's likely causing this discrepancy, and how would you debug it?
  2. 2You are designing a microservice where API Gateway triggers a Lambda. You need to choose between 'Lambda Proxy Integration' and 'Lambda Custom Integration'. What are the practical tradeoffs of each, and in what scenario would you absolutely avoid Proxy Integration?

5-8 years experience

  1. 1We are expecting a massive traffic spike on an API Gateway and Lambda endpoint. What are the failure modes we need to design for regarding concurrency limits, cold starts, and downstream database overload? How would you mitigate these at the API Gateway and Lambda levels?
  2. 2Your team is building a public-facing API where some endpoints require JWT authentication and others are public. How would you architect the authentication layer using API Gateway and Lambda? Would you use Cognito, API Gateway Lambda Authorizers, or handle auth inside the downstream Lambda itself? Why?

8+ years experience

  1. 1We have a legacy monolithic API running on EC2 that we want to migrate to a serverless architecture using API Gateway and Lambda. How would you design a strangler migration pattern to safely shift traffic route-by-route without downtime, and how do you manage shared state and database connection pooling during this transition?
  2. 2As a Principal Architect, you need to define the organization's standard for API design. When choosing between API Gateway HTTP APIs vs REST APIs for our Lambda-backed microservices, what architectural, cost, and feature-support factors dictate which one teams should use?

Follow-up Questions

  • How does the 29-second API Gateway timeout limit affect your Lambda design, and how do you handle long-running tasks?
  • What is the difference in payload format between API Gateway payload format version 1.0 and 2.0?
  • How would you implement rate limiting or throttling to protect your Lambda from being overwhelmed?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.