Your team is using AWS API Gateway and Lambda function to maintain an API endpoint.
Recently, there is a change in the Lambda function which adds some new data in the response body.
The Lambda function is upgraded and a new API is added to support the change.
The team wants to keep both version1 and version2 of the API to be available simultaneously to your API consumers.
How should you modify the version1 API in API Gateway to behave as the V1 consumers expect?
Click on the arrows to vote for the correct answer
A. B. C. D.Correct Answer - D.
Refer to.
https://aws.amazon.com/blogs/compute/using-api-gateway-mapping-templates-to-handle-changes-in-your-back-end-apis/for the example of how to use API Gateway mapping templates to handle backend changes.
In order to modify the backend response, a mapping template should be added in the Integration Response of the old API:
Option A is incorrect: Because mapping template can only be configured in Integration Request or Integration Response.
Option B is incorrect: For this option, changes may be needed for the backend.
And the Lambda function needs to differentiate API versions and react accordingly.
For this scenario, the best way is to modify Integration Response.
Option C is incorrect: Because Header Mapping is incorrect to remove data in the response body.
Option D is CORRECT: Because the mapping template is suitable to adjust the response from the back end, the response behaves exactly the same for original API consumers.
To keep both version1 and version2 of the API available simultaneously and maintain the same behavior for version1 consumers, we need to modify the version1 API in API Gateway. We can achieve this by modifying the Integration Response of version1 API.
Option A - Add a mapping template in the Method Response of version1 API to remove the new data in response to keep the same behaviors as before. This option will modify the response structure that is sent back to the client. This may break the existing clients who are expecting a specific response structure. Hence, this option is not feasible.
Option B - In the Integration Request of version1 API, add a mapping to inform the backend Lambda to remove the new data in the relevant response. This option will modify the request that is sent to the Lambda function. We can add a mapping template in the Integration Request of version1 API to remove the new data from the request. However, this will not help in removing the new data from the response. Hence, this option is not feasible.
Option C - In the Integration Response of version1 API, add a new Header Mapping to remove the new data which comes from the backend. This option will add a new header mapping in the Integration Response of version1 API to remove the new data. However, this will not remove the new data from the response body. Hence, this option is not feasible.
Option D - Add a mapping template in the Integration Response of version1 API to remove the new data so that the response is transformed to the original format. This option will modify the response that is sent back to the client. We can add a mapping template in the Integration Response of version1 API to remove the new data from the response. This will transform the response to the original format and maintain the same behavior for version1 consumers. Hence, this option is feasible.
In summary, the correct answer is option D - Add a mapping template in the Integration Response of version1 API to remove the new data so that the response is transformed to the original format.