Building an API Gateway with Path and Query String Parameters.

Building an API Gateway with Path and Query String Parameters.

We’ll build an AWS API Gateway that uses path parameters and query string parameters, connected to a Lambda function.

Step 1: Sign to the AWS Management Console

1. Click on the Open Console button, and you will get redirected to AWS Console in a new browser tab.

2. Copy your User Name and Password in the Lab Console to the IAM Username and Password in the AWS Console and click on the Sign in button.

Step 2: Create the Lambda Function

In this task, we will create a Lambda function by providing the required configurations like name, runtime, roles, etc.

1.Navigate to services menu at the top, click the Lambda under the compute section.

2. Click on create function button.

=.Select author from scratch in create function.

=.Function name: Jeevi API (your API name).

=.Runtime: python 3.13

=.under change default execution role .

=.Role Name: Enter MyRole.

=.leave other option as a default.

=.Click on the create function button.

3.Once the lambda function is created successfully , it will look like screenshot below:

4.Under Function code:

Replacing the existing code with in below python code.

5.Click the deploy button.

Step 3: Create an API Gateway

  • Navigate to the services menu at the top, then click on API Gateway.
  • Click on the Build button in REST API.

Select protocol as REST.

1.Create a new API : Choose a New API

2.Under settings

     *  API Name : JeeviAPI (your API name)

    * Leave other option as default.

    * Click on the create API button.

Step 4: Creating a resources with path parameter

1.Once API created, click on Create Resources.

  • Resources name – Enter {servername}
  • Resources name should be inside this bracket {}

2. Then click on the Create resources

Step 5: Create a method

  1. After created a resources, then click on Create Method button.
  2. Select Get in Method type.
  3. Setup:
  4.  Integration Type : Select Lambda Function
  5. Lambda Region: us-east-1
  6. Lambda function : Enter API and select the function name you created from the list.
  7. Leave everything as default.

Then click create method button.

Step 6: Add a query string parameter

  1. Click on the method request link in the Get method page.
  2. Under Method request settings:
  3. Click on the Edit button.
  4. Request valitator:  Select Validate body, query string parameters and headers.

3.Under URL Query String Parameters:

  •   Click on the Add query string button.
  • Name : Enter emailed
  • Check the  checkbox below Required.
  • Then click on create method button.

4.Click on the Integration Request link in the GET method page.

5. Click on Edit and scroll down to the bottom and select Mapping Templates.

6.  Request Body passthrough: Select When there are no templates defined (recommended).

7. Click on Add mapping template.

8.  Content-Type: enter application/json.

9. Again, scroll down to the page bottom.

10. Generate template: Select Method Request passthrough from the list.

11. Click on the Save button.

Step 6: Deploy the API Gateway

  1. Once the resource and the method have been created successfully, you can deploy the API.

Now again, select the GET from the hierarchy.

  1. Click on Deploy API.
  2. Select the Deployment Stage in the drop-down as New Stage.
  3. Enter Stage Name: TestingAPI And optionally enter a Stage Description: Testing environment for my API.
  1. Click on the Deploy button.
  2. Once the API has been deployed, navigate to Stages and click on the stage you created

Now, click on the GET method.

Copy and paste the Invoke URL to a new browser. 

Now replace {servername} with production and then add mailid.

Now you will receive the GET request’s response from the API.

Conclusion.

Building an API Gateway that correctly handles path and query string parameters is essential for creating flexible, maintainable, and scalable APIs. Path parameters define the structure of your API and identify specific resources, while query string parameters provide additional filtering and customization options. By properly configuring parameter mappings, validation, and integration with backend services, you ensure consistent data flow, improved performance, and a cleaner client experience. In short, mastering path and query parameter handling at the gateway level sets the foundation for robust, user-friendly API design and long-term scalability.

  • For more information about AWS API Gateway, you can refer to Jeevi’s page.
shamitha
shamitha
Leave Comment
Share This Blog
Recent Posts
Get The Latest Updates

Subscribe To Our Newsletter

No spam, notifications only about our New Course updates.

Enroll Now
Enroll Now
Enquire Now