2

When I query my Invoke URL as https://xxx.execute-api.yyy.amazonaws.com/test/q?apiKey=AAA with my below setup my backend receives a call as https://api.mysite.com/q?apiKey=AAA&apiKey=111: one apiKey=AAA comes from the client, the second one - apiKey=111 comes from the Integration Request configuration.

Question: What/How should I configure an integration that apiKey=AAA either removed from the client call or replaced on the integration step with 111 value so that only one apiKey comes to the backend?

Note:

  • with proxy passthrough integration the Mapping Templates are not available;
  • the reason for such configuration is that my legacy backend has a big amount of endpoints which is not possible to configure individually.

My setup:

  • I have created a new REST API.
  • Then I have created a new Configure as a Proxy resource named proxy with a Resource Path /{proxy+} with the following setup for ANY method as a proxy integration:
    • Integration type HTTP Proxy
    • Endpoint URL: https://api.mysite.com/{proxy}
    • Content Handling: Passthrough
  • As a next step, I have configured an Integration Request for my /{proxy+} - ANY by adding a new query string to the URL Query String Parameters section:
    • Name: myApiKey
    • Mapped from: '111'
  • Then I click Deploy API to test stage and getting Invoke URL, let's say: https://xxx.execute-api.yyy.amazonaws.com/test.

1 Answer 1

1

Even with Proxy Integration, we can still override Request & Response. Here is the blog. Let me try to summarize.

  • Ensure that Use Proxy Integration is unchecked
  • Simple VTL template in Mapping Template to replace apiKey queryParameter.
  #set($newApiKey = "abcd")
  $input.json("$")
  #set($context.requestOverride.querystring.apiKey = $newApiKey)
  • Add Method Responses example response codes 200, 400 and 500.
  • Add Integration Response for each status code for each response codes for example http status for 2xx 2\d{2} with pass through behaviour.

Lets say we have a proxy setup for path /someapi/sompath. Above template will replace /someapi/sompath?apiKey=100 to {proxy}?apiKey=abcd

Sign up to request clarification or add additional context in comments.

6 Comments

The replacement works, but this approach brings a lot of problems as it requires to do a lot of configuration in Method Response and Integration Response even for delivering CORS headers back to the client, as according to the doc for the ANY method in a proxy integration, any applicable CORS headers will not be set. Same for Content-Type which is not always json. Please, advise what should I do to deliver all headers through Integration Response from the back-end to the client with less effort.
For a proxy integration, we can't make any changes to Method Response or Integration Response. The change in this answer is for Integration Request. and Response from backend is sent to client without changes and we don't need to do any setup for it and we can't alter response headers. And to handle CORS, we need to add OPTIONS method, with MOCK integration and return necessary headers back in Integration Response, leaving 'ANY` as is.
If I leave an Integration Response chain untouched after removing a Use Proxy Integration flag in Integration Request THEN I receive the following error: Execution failed due to configuration error: No match for output mapping and no default output mapping configured. Endpoint Response Status Code: 200. So, unchecked Use Proxy Integration affects to response chain as well.
Ok. I tested it out, it looks like we needed to setup Response as well. 1. setup Method response 2. Setup Integration Response. I will update my answer.
@vaa , overall yes, overriding Integration Request does seem to affect Integration Response, which is weird.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.