2017-12-26 7 views
0

그래서 나는 몇 시간 동안 인터넷 검색을하고이 중 아무 것도하지 않았다. 이것은 "노력이 적은 게시물"이 아닙니다.Lambda @ Edge 함수에 리디렉션을 지시하는 코드는 무엇입니까?

다음은 내가 시도한 코드의 예입니다. 작동하지 않습니다. 또한 response.headers=[{Location:"foo"}] 또는 response.headers=[{location:"foo"}] 또는 내가 시도한 다른 8 가지 방법과 같은 응답을하지 않습니다.

exports.handler = (event, context, callback) => { 
    if(request.uri === "/") { 
    var response = { 
     statusCode: 301, 
     headers: { 
      "location" : [{ 
       key: "Location", 
       value: "foo" 
      }] 
     }, 
     body: null 
    }; 
    callback(null, response); 
} 

내가 해봤 다음 링크 :

답변

3
  • http://www.davekonopka.com/2016/serverless-aws-lambda-api-gateway.html 당신은 당신의 질문에이 예제에 대한 링크를 언급; 그것은 람다 프록시 통합 작업을해야합니다

    'use strict'; 
    
    exports.handler = function(event, context, callback) { 
    var response = { 
        statusCode: 301, 
        headers: { 
         "Location" : "http://example.com" 
        }, 
        body: null 
    }; 
    callback(null, response); 
    }; 
    

    소스 : http://blog.ryangreen.ca/2016/01/04/how-to-http-redirects-with-api-gateway-and-lambda/

    업데이트 :

    그렇지

    , this page of example functions에서이 예제를 사용하여 시도해보십시오에 그대로 주먹 URL을의

    'use strict'; 
    
    exports.handler = (event, context, callback) => { 
    /* 
    * Generate HTTP redirect response with 302 status code and Location header. 
    */ 
    const response = { 
        status: '302', 
        statusDescription: 'Found', 
        headers: { 
         location: [{ 
          key: 'Location', 
          value: 'http://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html', 
         }], 
        }, 
    }; 
    callback(null, response); 
    }; 
    
  • +0

    내가 말했던 URL 목록. 너는 이것에 대해 어떤 지식이 있니? 절대 URL을 제공하지 않을 수도 있습니다. 그 코드가있는 오류 메시지가 올바르게 기억 되더라도 헤더에 관한 것이 배열이어야합니다. ... 당신이 연결 한 코드가 내가 시도한 첫 번째 것입니다. 당신의 반응이 농담인지 확실하지 않습니다. – user875234

    +0

    네,하지만 Lambda Proxy Integration과 함께 사용하고 있습니까? – Marathon55

    +1

    람다는 클라우드 프론트의보기 요청 및 원본 요청 트리거에서 트리거됩니다. 나도 API 게이트웨이 API가 뭔지 모르겠다. – user875234