Learn how to use API Gateway mock integration to test your mobile app without invoking the backend service. This tutorial will show you how to use a request mapping template to select the mock integration response based on the request.
Table of Contents
Question
A developer is creating a mobile app that calls a backend service by using an Amazon API Gateway REST API. For integration testing during the development phase, the developer wants to simulate different backend responses without invoking the backend service.
Which solution will meet these requirements with the LEAST operational overhead?
A. Create an AWS Lambda function. Use API Gateway proxy integration to return constant HTTP responses.
B. Create an Amazon EC2 instance that serves the backend REST API by using an AWS CloudFormation template.
C. Customize the API Gateway stage to select a response type based on the request.
D. Use a request mapping template to select the mock integration response.
Answer
B. Create an Amazon EC2 instance that serves the backend REST API by using an AWS CloudFormation template.
Explanation
The correct answer is D. Use a request mapping template to select the mock integration response.
Here is an explanation of why this solution will meet the requirements with the least operational overhead:
- The problem is that the developer is creating a mobile app that calls a backend service by using an API Gateway REST API, and wants to simulate different backend responses without invoking the backend service. This can help the developer to test the app’s behavior and functionality under various scenarios, such as success, failure, or error responses.
- To solve this problem, the developer needs to use a feature of API Gateway that allows mocking backend responses based on the request parameters. Mocking is a technique that simulates the behavior of a real system or service by returning predefined responses. It can be useful for testing and debugging purposes, as it can reduce the dependency on external systems and services, and speed up the development process.
- The solution that meets the requirements with the least operational overhead is to use a request mapping template to select the mock integration response. A request mapping template is a script that transforms the incoming request data into a format that is expected by the backend integration. It can also be used to define conditional logic and expressions that can alter the request data or select a different integration type based on the request parameters. A mock integration response is a predefined response that is returned by API Gateway without invoking any backend service. It can be configured with different status codes, headers, and body content.
- The developer can use a request mapping template to select the mock integration response by using the integration.response property in the template. This property allows the developer to specify which mock integration response to return based on the request parameters, such as query strings, headers, or path variables. For example, if the developer wants to return a mock success response for requests that have a status=success query string parameter, and a mock error response for requests that have a status=error query string parameter, the developer can use the following request mapping template:
{
"integration.response": {
"selectionPattern": "$input.params('status')",
"caseMappings": {
"success": "200",
"error": "500"
}
}
}
- This solution will meet the requirements with the least operational overhead because it will enable the developer to simulate different backend responses without invoking the backend service, and without creating any additional resources or services. The developer can easily configure and modify the request mapping template and the mock integration responses using the API Gateway console or CLI.
Therefore, option D is the correct solution that will meet the requirements with the least operational overhead. Option A is incorrect because it will require creating and managing a Lambda function, which will add more resources and costs to the application. Option B is incorrect because it will require launching and managing an EC2 instance and a CloudFormation template, which will add more resources and costs to the application. Option C is incorrect because it will require creating and managing an OpenSearch Service instance, which is not designed for mocking backend responses.
The latest AWS Certified Developer – Associate DVA-C02 certification actual real practice exam question and answer (Q&A) dumps are available free, which are helpful for you to pass the AWS Certified Developer – Associate DVA-C02 exam and earn AWS Certified Developer – Associate DVA-C02 certification.