- Newest
- Most votes
- Most comments
From your query, I understand that you want to access the headers returned from the backend integration (NLB having EC2 in the Target group) using a mapping template(VTL). Aditionally, the EC2 instance is having an Apache server installed on it. There are two ways to integrate the backend with API Gateway: Proxy Integration, Non-Proxy Integration.
Case1 : Proxy Integration
If, the API Gateway (REST) is using a Proxy Integration to integrate with NLB, the headers cannot be modified using mapping templates (VTL). This is because when Proxy Integration is used, the output returned from the backend cannot be modified in the integration response (using the mapping template) and the response is returned as-is from the backend.
Case2 : Non-Proxy Integration
Using, Non-Proxy Integration with NLB, there are two ways in which Headers can be returned from the Backend.
If the headers from the backend are present in Response Headers field when the API Gateway is tested out from the console, it is not possible to access headers/query strings/status codes etc. returned from the backend in the Response Body Mapping templates using VTL, and you can only access the Response Body from the backend in the templates.
The only workaround currently is to send the required headers/status codes to the response body and access it in the mapping template after that or use the header mapping section in integration response. Further, you can refer this document for using header mapping section in Integration response[1].
That being said, there is an existing feature request for accessing headers/query strings/status codes present in the Response Headers field. I went ahead and added your voice to this feature request by doing a +1 on the feature request. Meanwhile, I request you to keep an eye on our What's New[2] and Blog pages[3] for any new feature announcements.
References:
[1] https://docs.aws.amazon.com/apigateway/latest/developerguide/request-response-data-mappings.html#mapping-response-parameters
[2] https://aws.amazon.com/new/
[3] https://aws.amazon.com/blogs/aws/
Relevant content
- Accepted Answerasked 2 years ago
- Accepted Answerasked a year ago
- Accepted Answerasked a year ago
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated 9 months ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 3 months ago