In this section, we will:
Add GET and POST methods to the /posts resource to retrieve and add posts.
Integrate with Lambda functions (getPosts, createPost).
Enable CORS and deploy the API for use in the frontend.
Test the API to ensure proper operation.
HTTP request handling: GET/POST methods allow the frontend to interact with the backend.
Lambda integration: Connect the API to Lambda to handle business logic.
Performance testing: Ensure the API returns correct results before integrating with the frontend.
Go to AWS Management Console and select API Gateway.
Open the BlogAPI API created in the previous step.
Create a GET method for /posts:
In Resources, select the /posts resource.
Select Actions → Create Method.
Select GET from the dropdown.
Integration type: Select Lambda Function.
Lambda Function: Select getPosts.
Click Save and confirm IAM permissions if prompted.

/posts:createPost function.
In Resources, select Actions → Enable CORS.
Accept the default values and click Enable CORS and replace existing CORS headers.

Select Actions → Deploy API.
Deployment stage: Select [New Stage] and name it (e.g. prod).
Click Deploy.
Save Invoke URL (e.g. https://gcnpmry3bd.execute-api.ap-southeast-1.amazonaws.com/prod).

Make sure CORS is enabled so that the React/Vite frontend can make requests to the API.
Save the Invoke URL for use in the frontend (step 6).
Check the IAM permissions of Lambda (lambda-blog-role) to ensure that API Gateway can call functions.
Use Postman or a browser to test:
GET <Invoke URL>/posts: Returns a list of posts from DynamoDB.
POST <Invoke URL>/posts with body:
{
"postId": "2",
"title": "Test Post",
"content": "This is a test post."
}

The API is up and running and ready to connect to the frontend.
Record the Invoke URL for use in the frontend configuration step.
