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.

답변 없음

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인