【发布时间】:2016-07-19 05:00:49
【问题描述】:
我想从处理程序返回一个值到 API 网关响应标头。
Handler.js
module.exports.handler = function(event, context, cb) {
const UpdateDate = new Date();
return cb(null, {
body: {
message: 'test'
},
header: {
Last-Modified: UpdateDate
}
});
};
“端点”中的 s-function.json
"responses": {
"400": {
"statusCode": "400"
},
"default": {
"statusCode": "200",
"responseParameters": {
"method.response.header.Cache-Control": "'public, max-age=86400'",
"method.response.header.Last-Modified": "integration.response.body.header.Last-Modified"
},
"responseModels": {
"application/json;charset=UTF-8": "Empty"
},
"responseTemplates": {
"application/json;charset=UTF-8": "$input.json('$.body')"
}
}
}
这可以工作。但我想知道如何使用“integration.response.header.Last-Modified”。我的处理程序回调格式错了吗?
编辑: “端点”中的 s-function.json
"integration.response.header.Last-Modified" 这不起作用。 我想知道特定的处理程序返回格式以将数据传递给“integration.response.header.Last-Modified”。
"responses": {
"400": {
"statusCode": "400"
},
"default": {
"statusCode": "200",
"responseParameters": {
"method.response.header.Cache-Control": "'public, max-age=86400'",
"method.response.header.Last-Modified": "integration.response.header.Last-Modified"
},
"responseModels": {
"application/json;charset=UTF-8": "Empty"
},
"responseTemplates": {
"application/json;charset=UTF-8": "$input.json('$.body')"
}
}
}
【问题讨论】:
-
乍一看这看起来是正确的,但我不明白你的问题。你是说这不起作用吗?如果没有,您看到了什么行为?
-
我想使用“integration.response.header.Last-Modified”,但我不知道 lambda 返回甲酸盐。
标签: aws-lambda aws-api-gateway serverless-framework