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.
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.
After creating the REST API, a confirmation message will appear at the top of the screen: Successfully created REST API.
In the ProductAPI section created, navigate to the Resources section, click Create Resource button.
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.
product
like step 6./products
resource and click Create method button: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.
/products
resource./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.