How to integrate AWS Lambda function with API Gateway

Photo by Jerry Zhang on Unsplash

How to integrate AWS Lambda function with API Gateway

Cloud computing with AWS

For this blog, be sure to have a Lambda setup and prepared already, if need help in the same refer : How to Setup and Execute your First AWS Lambda function

Now that you have Lambda ready. Let's start with setting up an API Gateway.

  • Navigate to Services > API Gateway

  • Click on Create API button:

    Look for the "Create API" button on the API Gateway dashboard and click on it.

    In the API creation wizard, select the type of API you want to create. Click on the "Build" button to proceed with your preferred choice.

  • Create an API step

    Add Integrations

    Set as Lambda
    Select the lambda you already created.

  • Configure Routes
    Provide a Route resource path
    Provide Method (GET/POST/PUT/DELETE)
    This is the URL path where your API will be accessible.

  • Define stages:
    Next, add a stage name for your API. The stage represents a specific deployment of your API (e.g., "development", "production", etc.).

  • If you didn't already set up the integration target:
    Go to API Gateway > Your API
    Add integration, select Lambda and Apply Integration target.

    Check the Grant API Gateway permission to invoke your Lambda function.
    Hit the create button.

  • Deploy your API
    After create your API, Hit the Deploy button.
    Select the stage that you've created earlier (e.g., "development", "production", etc.) from the dropdown menu.

    Confirm the deployment by clicking on the "Deploy" button. After deployment you will get dashboard like this

  • Use the API:

    To use your API, simply copy the provided endpoint URL (usually displayed on the dashboard or deployment confirmation page) along with your route.

Now, we good to monitor usage, set up custom domains, configure authorizers, etc. with your API Gateway.