Search code examples
amazon-web-servicessetcookiehttp-status-code-302

AWS API Gateway : Use 302 redirect and set-cookie header


I used AWS API Gateway to redirect in response.

simple flow : aaa.com ====> API Gateway & Lambda ==[302 redirect]==> bbb.com

It worked well when following the blog. However, I couldn't set cookie at bbb.com.

I followed the blog and defined another “Set-Cookie” header. My Lambda code snippet listed below.

context.succeed({
    location : "http://192.168.173.193:3030",
    setCookie: "path=/;sessionID=1234;domain=null;"
});

Solution

  • Did you update your Response Parameters?

    In that blog post notice the responseParameters section of the Swagger Example.

    responseParameters:
              method.response.header.Location: "integration.response.body.location"
    

    You need to add another line to that mapping the Set-Cookie parameter. Something like:

    responseParameters:
              method.response.header.Location: "integration.response.body.location"
              method.response.header.Set-Cookie: "integration.response.body.setCookie"