Redirecting from aws-api gateway using 302 response

I am trying to make redirection work in the AWS API gateway. I configured the method response to include Location in the header and the Integration Response response, I set the parameter as: Location = integration.response.body.location. however, when I test the API, instead of redirecting me to a place, it just shows me the text for the location on the API page. Has anyone come across this before?

The line shown is actually the right place, but the API does not redirect me to this URL.

+5
source share
6 answers

Are you sure the API endpoint is returning 302?

, 2xx 3xx, 302, . "" . 2xx 3xx .

0

, . I, , , , - . .

0

-, "location". . Node.js integration.response.body.errorType. , :

// Returns 302 or 301
var err = new Error("HandlerDemo.ResponseFound Redirection: Resource found elsewhere");
err.name = "http://a-different-uri";
context.done(err, {});

.: https://aws.amazon.com/blogs/compute/redirection-in-a-serverless-api-with-aws-lambda-and-amazon-api-gateway/

0

2018. Lambda API Gateway:

module.exports.handler = (event, context, callback) => Promise.resolve(event)
  // .then(doStuffWithTheEventObject)
  .then(() => callback(null, {
    statusCode: 302,
    headers: {
      Location: 'https://gohere.com',
    },
  })) // Success!
  .catch(callback); // Fail function with error

https://blog.rowanudell.com/redirects-in-serverless/

0

URL API Gateway AWS Lambda. OpenAPI 3.0, :

      DefinitionBody:
        openapi: "3.0.0"
        paths:
          "/":
            get:
              responses:
                "302":
                  description: "302 response"
                  headers:
                    Location:
                      schema:
                        type: "string"
                  content: {}
              x-amazon-apigateway-integration:
                responses:
                  default:
                    statusCode: "302"
                    responseParameters:
                      method.response.header.Location: "'https://github.com/lukedemi/adventbot'"
                requestTemplates:
                  application/json: "{\"statusCode\": 200}"
                passthroughBehavior: "when_no_match"
                type: "mock"
0

All Articles