> ## Documentation Index
> Fetch the complete documentation index at: https://cloud-architect.ipoint-labs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Build API Gateway with path parameter and Query string parameter

> Hands-on lab · 45m

Launch this lab in the IP Lab Portal, then follow the steps below in the AWS console.

<a className="ip-lab-portal-btn" href="https://labs.intellectualpoint.com/labs/build-api-gateway-with-path-parameter-and-query-string-parameter" target="_blank" rel="noreferrer">
  Open IP Lab Portal
</a>

## Overview

### Lab Details

1. This lab walks you through the steps to create an API Gateway with path and query string parameters and integrate it into the Lambda function.
2. You will practice using Amazon API Gateway.
3. Duration of the Lab: **45 minutes.**
4. AWS Region: **US East (N. Virginia) us-east-1**.

### Introduction

#### Amazon API Gateway

* Amazon API Gateway is a **fully managed service** that makes it easy for developers to create, publish, maintain, monitor, and secure APIs at any scale.
* APIs act as the **front door** for applications to access data, business logic, or functionality from your backend services.
* API Gateway handles all the tasks involved in accepting and processing up to hundreds of thousands of concurrent API calls, including traffic management, CORS support, authorization and access control, throttling, monitoring, and API version management.
* Using API Gateway, you can create RESTful APIs and WebSocket APIs that enable real-time two-way communication applications. API Gateway supports containerized and serverless workloads, as well as web applications.
* AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume.
* With Lambda, you can run code for virtually any type of application or backend service - all with zero administration. Just upload your code and Lambda takes care of everything required to run and scale your code with high availability. You can set up your code to automatically trigger from other AWS services or call it directly from any web or mobile app.

### Architecture Diagram

<img src="https://mintcdn.com/ip-cloud-architect-pathway/cFGhMl2S4kekNdRt/images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/001.png?fit=max&auto=format&n=cFGhMl2S4kekNdRt&q=85&s=0d627bab8892ca589cc338ed5084f2f6" alt="" width="3750" height="1538" data-path="images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/001.png" />

### Task Details

1. Sign in to the AWS Management Console.
2. Create a Lambda Function.
3. Create a new API Gateway.
4. Create a Resource with a path parameter.
5. Create a Method.
6. Add a query string parameter.
7. Test the API

### Launching Lab Environment

1. To launch the lab environment, Click on the **Start Lab** button.
2. Please wait until the cloud environment is provisioned. It will take less than a minute to provision.
3. Once the lab is started, you will be provided with an **IAM username**, **Password**, **Access** **Key**, and **Secret** **Access** **Key**.

> **Note**: You can only start one lab at any given time

## Lab guide

### Lab Steps

#### Task 1: Sign in 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. On the AWS sign-in page,

   * Leave the Account ID as default. Never edit/remove the 12-digit Account ID present in the AWS Console. otherwise, you cannot proceed with the lab.
   * Now 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.
3. Once Signed In to the AWS Management Console, Make the default AWS Region as **US East (N. Virginia) us-east-1.**

#### Task 2: Create a Lambda Function

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

1. Navigate to the **Services** menu at the top, then click on **Lambda** under the **Compute** section.
2. Click on the **Create function** button.

   * Select **Author from Scratch**
   * Function Name: Enter ***WhizlabsAPI***
   * Runtime: Select **Python 3.9**
   * Under **Change default execution role**
   * Choose **Use an existing role.**
   * Role Name: Enter ***Whiz\_lambda\_role-\<random\_number>***

<img src="https://mintcdn.com/ip-cloud-architect-pathway/cFGhMl2S4kekNdRt/images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/002.png?fit=max&auto=format&n=cFGhMl2S4kekNdRt&q=85&s=246f44d6c9aac5d0aec2cdad1ac7e139" alt="" width="1899" height="516" data-path="images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/002.png" />

* Leave other options as default.
* Click on the **Create function** button.

3. Once the Lambda Function is created successfully, it will look like the screenshot below:

<img src="https://mintcdn.com/ip-cloud-architect-pathway/cFGhMl2S4kekNdRt/images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/003.png?fit=max&auto=format&n=cFGhMl2S4kekNdRt&q=85&s=bd5793c206a9c41888250c39605869cd" alt="" width="2416" height="1156" data-path="images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/003.png" />

4. Under **Function code**:

   * Replace the existing code with the below Python code.

```python theme={null}
import json

def lambda_handler(event, context):
    # Path parameter passed to Lambda function
    servername = event["params"]["path"]["servername"]

    # Query string parameter passed to Lambda function
    email_id = event["params"]["querystring"]["emailid"]

    return {
        "Path Parameter": servername,
        "Query string Parameter": email_id
    }
```

5. Click the **Deploy** button.

#### Task 3: Create an API Gateway

1. Navigate to the **Services** menu at the top, then click on **API Gateway** in the **Network and Content Delivery** section.
2. Click on the **Build** button in REST API.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/cFGhMl2S4kekNdRt/images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/004.png?fit=max&auto=format&n=cFGhMl2S4kekNdRt&q=85&s=c035a56911b4806102ab8e138699aad6" alt="" width="1125" height="271" data-path="images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/004.png" />

3. Select Protocol as **REST**
4. Create a new API: Choose a **New API.**
5. Under **settings**:

   * API name : Enter ***WhizlabAPI***
   * Leave other options as default\*\*.\*\*
   * Click on the **Create API** button.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/cFGhMl2S4kekNdRt/images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/005.png?fit=max&auto=format&n=cFGhMl2S4kekNdRt&q=85&s=c5612eb1c9bc6f7c6e47457edc63cf84" alt="" width="1628" height="1236" data-path="images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/005.png" />

#### Task 4: Creating a Resource with a path parameter

1. Once the API is created, click on **Create Resource**

* Resource Name: Enter ***\{servername}***
* **Note**: The resource name should be placed inside flower brackets **\{ }**
* Leave everything as default.

3. Now click on the **Create Resource** button.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/cFGhMl2S4kekNdRt/images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/006.png?fit=max&auto=format&n=cFGhMl2S4kekNdRt&q=85&s=d8196fc9c2f2ab07671222186b0b6616" alt="" width="1462" height="742" data-path="images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/006.png" />

#### Task 5: Creating a Method

1. Once you create a resource, click on **Create Method** button.

2. From the drop-down, select **GET.**

3. **Setup**:

* Integration Type: Select **Lambda Function**
* Lambda Region: select **us-east-1**
* Lambda function: Enter ***WhizlabsAPI*** and select the function name you created from the list.
* Leave everything else as default.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/cFGhMl2S4kekNdRt/images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/007.png?fit=max&auto=format&n=cFGhMl2S4kekNdRt&q=85&s=c01e10022e0537c9af38a26e59dab850" alt="" width="1960" height="1630" data-path="images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/007.png" />

4. Click on the **Create Method** button.

   * **Note:**  If any pop-ups appear, click on the **OK** button.
5. Once the method has been created, your screen will look similar to the screenshot below:

<img src="https://mintcdn.com/ip-cloud-architect-pathway/cFGhMl2S4kekNdRt/images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/008.png?fit=max&auto=format&n=cFGhMl2S4kekNdRt&q=85&s=205d9370e65827c2aa8cc3c0ca01b402" alt="" width="2424" height="700" data-path="images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/008.png" />

#### Task 6: Add a query string parameter

1. Click on the **Method Request** link in the **GET** method page.

2. Under **Method request Settings** :

   * Click on the **Edit** button.

* Request Validator: Select **Validate body, query string parameters, and headers**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/cFGhMl2S4kekNdRt/images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/009.png?fit=max&auto=format&n=cFGhMl2S4kekNdRt&q=85&s=c948844f9b980f796e2aaa4f74c99de0" alt="" width="1452" height="658" data-path="images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/009.png" />

3. Under **URL Query String Parameters**:

   * Click on the **Add query string** button.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/cFGhMl2S4kekNdRt/images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/010.png?fit=max&auto=format&n=cFGhMl2S4kekNdRt&q=85&s=34abf3e0834890b7c8a1d3bb6dba339f" alt="" width="1468" height="330" data-path="images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/010.png" />

* Name: Enter ***emailid***
* Check the checkbox below **Required.**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/cFGhMl2S4kekNdRt/images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/011.png?fit=max&auto=format&n=cFGhMl2S4kekNdRt&q=85&s=08331c372d728ac8dc0d7b53afa2a2da" alt="" width="1450" height="382" data-path="images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/011.png" />

4. Click on **Save**.

5. Click on the **Integration Request** link in the GET method page.

6. Click on **Edit** and Scroll down to the bottom and select **Mapping Templates.**

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

8. Click on **Add mapping template.**

9. Content type: Enter ***application/json***

10. Again, scroll down to the page to the bottom.

11. Generate template: Select **Method Request passthrough** from the list.

12. Click on the **Save** button.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/cFGhMl2S4kekNdRt/images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/012.png?fit=max&auto=format&n=cFGhMl2S4kekNdRt&q=85&s=d76ee0a0ba3bee1caf073a93194c6459" alt="" width="1452" height="1614" data-path="images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/012.png" />

**Note:** Clicking on the save button won't redirect you to any page, but make sure you click the save button.

#### Task 7: Deploy the API Gateway

1. Once the resource and the method have been created successfully, you can deploy the API.
2. Now again, select the **GET** from the hierarchy.
3. Click on the **Deploy API**.
4. Select the Deployment Stage in the drop-down as **New Stage**.
5. Enter Stage Name: ***TestingAPI*** and Stage description as ***Testing environment for my WhizlabsAPI***.
6. Click on the **Deploy** button.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/cFGhMl2S4kekNdRt/images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/013.png?fit=max&auto=format&n=cFGhMl2S4kekNdRt&q=85&s=1c8870521a59f2608072d9517181f6fa" alt="" width="1086" height="1036" data-path="images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/013.png" />

6. Once the API has been deployed, navigate to **Stages** and click on the stage name. You will be able to see the following:

<img src="https://mintcdn.com/ip-cloud-architect-pathway/cFGhMl2S4kekNdRt/images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/014.png?fit=max&auto=format&n=cFGhMl2S4kekNdRt&q=85&s=833adab4a2c4b25a0828678b06ee8b4b" alt="" width="1688" height="592" data-path="images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/014.png" />

7. Now click on the **GET** method.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/cFGhMl2S4kekNdRt/images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/015.png?fit=max&auto=format&n=cFGhMl2S4kekNdRt&q=85&s=090064b52761eaf6c3acb05a5b269f60" alt="" width="508" height="334" data-path="images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/015.png" />

8. Copy and Paste the **Invoke URL** in a new tab of your browser.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/cFGhMl2S4kekNdRt/images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/016.png?fit=max&auto=format&n=cFGhMl2S4kekNdRt&q=85&s=37dda8dc77a62cf417d72f2d917f7d44" alt="" width="1152" height="122" data-path="images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/016.png" />

9. Now replace **\{servername}** with ***Production*** and then add **?emailid=[whizlabs.user1@gmail.com](mailto:whizlabs.user1@gmail.com)**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/cFGhMl2S4kekNdRt/images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/017.png?fit=max&auto=format&n=cFGhMl2S4kekNdRt&q=85&s=b2aac19572eb4163a14180243d7d5d73" alt="" width="1046" height="108" data-path="images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/017.png" />

10. You will receive the GET request's response from the API. Here's an example:

<img src="https://mintcdn.com/ip-cloud-architect-pathway/cFGhMl2S4kekNdRt/images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/017.png?fit=max&auto=format&n=cFGhMl2S4kekNdRt&q=85&s=b2aac19572eb4163a14180243d7d5d73" alt="" width="1046" height="108" data-path="images/labs/build-api-gateway-with-path-parameter-and-query-string-parameter/017.png" />

> ##### Do you know ?
>
> Path parameters can expose sensitive information if not handled properly. For example, if you include confidential information directly in the URL path, it might end up in server logs or browser history. It's important to handle such data carefully and consider alternatives like request bodies or headers for sensitive information.

1. Once the lab steps are completed, please click the **Validation** button on the right side panel.
2. This will validate the resources in the AWS account and show you whether you have completed this lab successfully or not.

### Completion and Conclusion

1. You have successfully created a Lambda function.
2. You have successfully created the API.
3. You have successfully created the API Resource and Method.
4. You have successfully created path and query string parameters.
5. You have successfully tested the API.

### End Lab

1. Sign out of AWS Account.
2. You have successfully completed the lab.
3. Once you have completed the steps, click on **End Lab** from the IP Lab Portal dashboard.

## What gets checked

When you press **Check my work**, the platform verifies each of these:

* **Create an AWS Lambda Function** — Check whether a Lambda Function is created or not
* **Create a API Gateway** — Check whether a REST/HTTP?WEBSOCKET API gateway is created or not

## Related help

* [FAQs and Troubleshooting](/aws-saa/support/faqs-and-troubleshooting)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.