4
votes

How do I create a mock integration in API Gateway to take a request to:

/products/{product}/bigFile.zip?platform={platform}&version={version}

And respond with a redirect to:

http://xyz.cloudfront.net/{product}/{platform}/{version}.zip

I've tried changing the request and response mapping templates, but I'm not sure how they're connected, since the AWS docs on mock integrations are pretty sparse. I can change the HTTP status code, but I can't get the Location header to populate based on the query parameters.

The broader context (in case I've committed the XY problem) is that I am building an API using AWS API Gateway. One of the API endpoints serves large files that won't meet the 10s response time limit from API gateway, so I want to redirect to another CDN link.

1
The timeout for API Gateway is not 10 seconds any more, it has been increased to 29 seconds (staying under the 30 second CloudFront timeout)jackko

1 Answers

2
votes

For MOCK integrations, think about the Integration Request template that defines the status code (ex. {"statusCode": 200}) as a mock status code for the backend. Excluding that aspect, the other components are the same. You'll have to define a Method Response for the redirect 3xx status code and include any headers you want to send in the response. Then on the Integration Response page you can set the values for the headers as static values using single quotes. So that would be where you define the Location header with whatever the redirect URL is, like 'https://other.endpoint.com'

Edit: Workaround using Lambda function echo

Set up Lambda function to echo payload. Next map the querystring to the request body like so:

Template:

{
  "q": $input.params('foo')
}

Assuming the Lambda function echos the same payload back, you would set the header mapping source in the Integration Response as:

integration.response.body.q