API Gateway - Custom gateway response headers

0

I'm trying to use the AWS API Gateway "Gateway responses" feature to set a custom header on specific authorization failure responses. The documentation in the console says:

Response headers

Specifies the response headers to return to the client. You can specify in single quotes an incoming request parameter or static value to return in the header.

No examples are given for how to utilize incoming parameters, and the typical VTL parameters are not valid. Specifically, I'm attempting to set Location header value to /shell?target=$context.path. I've tried entering this in as many ways as I can guess but I either get an "Invalid mapping expression specified" error or the value I put is just returned as a plain string (i.e. not interpolated).

I'm able to work around the issue by returning a full HTML page using the "Response templates" section on the same page, reference $context.path, and use a meta-refresh to redirect the browser. It works, but I would much rather use the Location header the way it's supposed to be.

I don't know why $context.path works in the following template but not the ones I've tried for the header:

<html>
    <head>
        <meta http-equiv="refresh" content="0;url=/shell?target=$context.path">
    </head>
    <body>
        Authorizing...
    </body>
</html>
  • I should probably add that inserting a Lambda call is not an acceptable solution. The HTML hack I have is better than maintaining more code.

沒有答案

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南