I want to response a 304 response with Last-Modified header.
At first I use Error response to implement.
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 in endpoints
"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')"
}
}
}
However, I find it on Lambda doc.
If an error is provided, callback parameter is ignored.
So, this doesn't work.
Is there any solution to response a 304 response with header?
Updated:
Is it possible to return a Error object and map responses 304 in s-function? Below code can't map to 304.
s-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);
I also try this. It can mapping to 304 but header can't get "integration.response.body.errorMessage.Last-Modified"
return cb(JSON.stringify({
"status" : "304 Not Modified",
"Last-Modified": UpdateDate
}), null);
I try $util.parseJson but not working on responseParameter.
Invalid mapping expression specified:$util.parseJson($input.path('$.errorMessage')).Last-Modified
"responseParameters": {
"method.response.header.Cache-Control": "'public, max-age=86400'",
"method.response.header.Last-Modified": "$util.parseJson($input.path('$.errorMessage')).Last-Modified"
},