04 / 06

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

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