2016-07-19 1 views
3

Last-Modified 헤더를 사용하여 304 응답에 응답하고 싶습니다.Api 게이트웨이 304가 Last-Modified 헤더로 응답합니다.

처음에는 구현하기 위해 오류 응답을 사용합니다. 엔드 포인트

"responses": { 
    "304 Not Modified.*": { 
     "statusCode": "304", 
     "responseParameters": { 
     "method.response.header.Last-Modified": "integration.response.body.Last-Modified" 
     }, 
     "responseModels": { 
     "application/json;charset=UTF-8": "Empty" 
     }, 
     "responseTemplates": { 
     "application/json;charset=UTF-8": "$input.json('$.body')" 
     } 
    }, 
    "default": { 
     "statusCode": "200", 
     "responseParameters": { 
     "method.response.header.Cache-Control": "'public, max-age=86400'", 
     "method.response.header.Last-Modified": "integration.response.body.Last-Modified" 
     }, 
     "responseModels": { 
     "application/json;charset=UTF-8": "Empty" 
     }, 
     "responseTemplates": { 
     "application/json;charset=UTF-8": "$input.json('$.body')" 

     } 
    } 
} 

에서

Handler.js

module.exports.handler = function(event, context, cb) { 
    const UpdateDate = new Date(); 
    return cb("304 Not Modified", { 
    "Last-Modified": UpdateDate, 
    "body":{ 
     "message": {} 
    } 
    }); 
}; 

S-function.json는 그러나, 나는 람다 문서에서 찾을.

오류가 제공되면 콜백 매개 변수가 무시됩니다.

따라서 작동하지 않습니다.

헤더가있는 304 응답에 응답하는 솔루션이 있습니까?

업데이트 :

그것의 기능에서 오류 객체와지도 응답 (304)를 반환 할 수 있습니까? 코드는 304

의-funtion.json

"responses": { 
    ".*304 Not Modified.*": { 
     "statusCode": "304", 
     "responseParameters": { 
     "method.response.header.Cache-Control": "'public, max-age=86400'", 
     "method.response.header.Last-Modified": "integration.response.body.errorMessage.Last-Modified" 
     } 
} 

Handler.js

return cb({ 
    "status" : "304 Not Modified", 
    "Last-Modified": UpdateDate 
), null); 

에 매핑 할 수 없습니다 아래 나는 또한이 시도. 그것은 304에 매핑 할 수 있지만 헤더는

return cb(JSON.stringify({ 
    "status" : "304 Not Modified", 
    "Last-Modified": UpdateDate 
}), null); 

나는 $ util.parseJson을 시도하지만 responseParameter 작동하지 "integration.response.body.errorMessage.Last은-수정"받을 수 없습니다.

잘못된 매핑 표현 지정 :. $ util.parseJson ($의 input.path ('. $ ERRORMESSAGE')) 마지막으로 수정,

"responseParameters": { 
     "method.response.header.Cache-Control": "'public, max-age=86400'", 
     "method.response.header.Last-Modified": "$util.parseJson($input.path('$.errorMessage')).Last-Modified" 
    }, 
+0

당신의 업데이트가 실제로 오류를 반환하지 않는 옵션 2에 라이언의 링크를보고하십시오 옵션을 살펴 있습니다. –

+0

@BobKinney 오류가 반환됩니다. cloudWatch 로그에서 : { "errorMessage": "{\"상태 \ ": \"304 수정되지 않음 \ "최종 수정 \": \ "2016-07-22T01 : 58 : 10.857Z \"} " } – Jim

+0

사이드 노트에서 304는 W3에 따라 응답 본문을 반환하지 않아야합니다. 첫 번째 예를 참고하십시오. – arjabbar

답변

2

이 API에 상태 304를 반환하는 방법을 람다 함수로부터 에러를 던질 필요가 있습니다. Lambda 함수의 오류 메시지에서 "Last-Modified"값을 반환하고 API 응답의 "Last-Modified"헤더로 라우팅 할 수 있습니다. 자세한 내용은

2 here

감사합니다, 라이언

+0

고마워요, 제게 많은 도움이됩니다. 그리고 내 질문을 업데이트합니다! – Jim

관련 문제