Create API Gateway

Create API Gateway

In this step of creating an API Gateway, we will create a REST API to act as an interface between the application and the Lambda Function. The API Gateway will define structured endpoints (e.g. /products, /product) to handle HTTP requests like GET, POST, PUT, and DELETE.


  1. Search for API Gateway in the search bar and click on API Gateway.

APIGateway

  1. In the Create API, scroll down REST API section, click Build button.

APIGateway

  1. In the Create REST API, provide the following details:
  • API Name: Enter a name for your API (e.g. ProductAPI)

  • Description: Add an optional description.

  • API Endpoint Type: Select Regional.

  • Click Create API button to proceed.

APIGateway

  1. After creating the REST API, a confirmation message will appear at the top of the screen: Successfully created REST API.

  2. In the ProductAPI section created, navigate to the Resources section, click Create Resource button.

APIGateway

  1. In the Create resource, add the following resources:
  • Resource Name: Enter a name for the resource: products

  • Click enable CORS (Cross Origin Resource Sharing).

  • Click Create resource button.

You need to enable CORS to allow the S3-hosted interface to send requests to API Gateway, since the interface and API Gateway may be on different domains or origins. If CORS is not enabled, the browser will block requests from the S3-hosted interface to the API Gateway due to a violation of the browser’s default security policy, known as the Same-Origin Policy.

APIGateway

  1. After creating the resource, a confirmation message will appear at the top of the screen: Successfully created resource.

APIGateway

  1. Similarly, create another resource: product like step 6.

APIGateway

  1. In the Resources, choose /products resource and click Create method button:

APIGateway

  1. In the Create method, Method details section provide the following details:
  • GET:

    • Method Type: select GET.

    • Integration Type: select Lambda Function.

    • Click enable Lambda proxy integration.

    • Select your current region (e.g. us-east-1). Select the Lambda Function name that you created earlier in section 4.2. Create Lambda Function (e.g. ProductCRUDFunction)

    • Scroll down and click Create method button.

Enable Lambda proxy integration: API Gateway passes all HTTP requests (headers, queries, body, methods) directly to Lambda. Lambda handles all logic and responses. Without enabling Lambda proxy integration: API Gateway only sends pre-configured data (Mapping Templates) to Lambda. Parameters and responses must be manually configured in API Gateway.

APIGateway

APIGateway

APIGateway

  • After creating the method, a confirmation message will appear at the top of the screen: the method was successfully created.

APIGateway

  • Similarly, create a POST method for /products resource.
  1. Similarly, for the /product resource, add the following methods:
  • GET: To fetch a product by ID.

  • PUT: To update a product.

  • DELETE: To delete a product.

  • Configure each method similarly by integrating it with the appropriate Lambda Function like step: 9, 10.

APIGateway

  1. We have completed creating REST API. Next we will Deploy API.