📖 Scenario: You are building a simple API using AWS API Gateway. This API will have a resource path and a method to handle HTTP requests.Think of this like setting up a new phone line (resource) and deciding what kind of calls (methods) it can take.
🎯 Goal: Create an AWS API Gateway REST API with a resource path /products and add a GET method to it.
📋 What You'll Learn
Create a REST API named StoreAPI
Add a resource with path part products
Add a GET method to the /products resource
💡 Why This Matters
🌍 Real World
APIs are the backbone of modern applications. Setting up resources and methods in API Gateway allows you to create scalable and secure APIs for your services.
💼 Career
Cloud engineers and developers often need to configure API Gateway resources and methods to expose backend services securely and efficiently.
Progress0 / 4 steps
1
Create the REST API
Create a REST API named StoreAPI using AWS SDK or AWS CLI syntax. Assign it to a variable called api.
AWS
Hint
Use create_rest_api method with name='StoreAPI'.
2
Add the /products resource
Add a resource with path part products to the REST API stored in api. Assign the new resource to a variable called products_resource.
AWS
Hint
Use create_resource with restApiId=api['id'], parentId=api['rootResourceId'], and pathPart='products'.
3
Add GET method to /products
Add a GET method to the products_resource. Use authorizationType='NONE' and assign the method response to a variable called get_method.
AWS
Hint
Use put_method with restApiId=api['id'], resourceId=products_resource['id'], httpMethod='GET', and authorizationType='NONE'.
4
Add integration for GET method
Add a MOCK integration to the GET method on products_resource. Use type='MOCK' and assign the integration response to a variable called get_integration.
AWS
Hint
Use put_integration with restApiId=api['id'], resourceId=products_resource['id'], httpMethod='GET', type='MOCK', and integrationHttpMethod='GET'.
Practice
(1/5)
1. What does a resource represent in AWS API Gateway?
easy
A. A URL path that clients can access
B. A backend database connection
C. A security policy for API access
D. A method to deploy the API
Solution
Step 1: Understand the role of resources in API Gateway
Resources define the URL paths that clients use to reach your API endpoints.
Step 2: Differentiate resources from other components
Resources are not backend connections, security policies, or deployment methods; they are URL paths.
Final Answer:
A URL path that clients can access -> Option A
Quick Check:
Resource = URL path [OK]
Hint: Resources are the API's URL paths clients call [OK]
Common Mistakes:
Confusing resources with backend services
Thinking resources are security settings
Mixing resources with deployment steps
2. Which HTTP method is correctly defined in AWS API Gateway to retrieve data?
easy
A. GET
B. POST
C. DELETE
D. PUT
Solution
Step 1: Identify the HTTP method for data retrieval
GET is the standard HTTP method used to retrieve or read data from a resource.
Step 2: Confirm other methods' purposes
POST creates data, DELETE removes data, and PUT updates data, so they are not for retrieval.
Final Answer:
GET -> Option A
Quick Check:
GET = retrieve data [OK]
Hint: GET method is for reading data from resources [OK]
Common Mistakes:
Using POST instead of GET to fetch data
Confusing DELETE with data retrieval
Mixing PUT with GET for reading data
3. Given this API Gateway setup: a resource /items with a POST method integrated to a Lambda function. What happens when a client sends a POST request to /items?
medium
A. The API Gateway returns a static mock response
B. The API Gateway returns a 404 Not Found error
C. The Lambda function is triggered to process the request
D. The request is ignored because POST is not allowed
Solution
Step 1: Understand the integration of POST method with Lambda
The POST method on the /items resource is connected to a Lambda function, so requests trigger that function.
Step 2: Analyze the client request effect
When a client sends a POST request to /items, API Gateway forwards it to Lambda for processing.
Final Answer:
The Lambda function is triggered to process the request -> Option C
Quick Check:
POST + Lambda integration = Lambda triggered [OK]
Hint: POST method triggers Lambda if integrated [OK]
Common Mistakes:
Assuming POST is not allowed without checking method setup
Thinking API Gateway returns 404 if resource exists
Confusing mock responses with Lambda integration
4. You created a resource /users and added a GET method, but clients get a 403 Forbidden error when calling it. What is the most likely cause?
medium
A. The client is using POST instead of GET
B. The resource path is misspelled
C. The API Gateway is not deployed
D. The method does not have an integration configured
Solution
Step 1: Check method integration setup
A 403 Forbidden often means the method exists but lacks proper integration or permissions.
Step 2: Rule out other causes
If the resource path was misspelled, the error would be 404. If API Gateway was not deployed, the error would differ. Using POST instead of GET would cause a 405 Method Not Allowed.
Final Answer:
The method does not have an integration configured -> Option D
Quick Check:
403 Forbidden = missing integration or permissions [OK]
Hint: 403 often means method lacks integration or permissions [OK]
Common Mistakes:
Confusing 403 with 404 or 405 errors
Ignoring deployment status
Assuming client method is always correct
5. You want to create an API with a resource /orders that supports both GET and POST methods. The GET method returns a mock response, and the POST method triggers a Lambda function. Which configuration correctly sets this up?
hard
A. Create /orders resource; add GET and POST methods both with MOCK integration
B. Create /orders resource; add GET method with MOCK integration; add POST method with Lambda integration
C. Create /orders resource; add GET method with Lambda integration; add POST method with MOCK integration
D. Create /orders resource; add GET and POST methods both with Lambda integration
Solution
Step 1: Match method to integration type
The GET method should use MOCK integration to return a static response without backend calls.
Step 2: Configure POST method to trigger Lambda
The POST method must be integrated with Lambda to process incoming data.
Step 3: Verify the correct combination
Create /orders resource; add GET method with MOCK integration; add POST method with Lambda integration correctly assigns MOCK to GET and Lambda to POST on the /orders resource.
Final Answer:
Create /orders resource; add GET method with MOCK integration; add POST method with Lambda integration -> Option B
Quick Check:
GET=MOCK, POST=Lambda [OK]
Hint: GET with MOCK, POST with Lambda for mixed behavior [OK]
Common Mistakes:
Swapping MOCK and Lambda integrations between methods
Using same integration for both methods incorrectly
Forgetting to create the resource before methods
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.