【发布时间】:2019-09-26 21:15:18
【问题描述】:
我想在 AWS lambda 上构建一个合适的 typescript 项目。
现在,我有以下定义:
export type HttpResponse = {
statusCode: number;
headers: {};
body: string;
}
export async function readCollection (event, context, callback): Promise<HttpResponse>{
console.log(event); // Contains incoming request data (e.g., query params, headers and more)
const data = [
{
id: "a7b5bf50-0b5b-11e9-bc65-6bfc39f23288",
name: "some thing",
uri: `/notifications/a7b5bf50-0b5b-11e9-bc65-6bfc39f23288`
}
]
const response = {
statusCode: 200,
headers: {
},
body: JSON.stringify({
status: "ok",
data: data
})
};
return response;
};
但是
我想使用官方定义,而不是我自定义的HttpResponse 类型。
但是我应该导入和返回哪个官方类型呢?
【问题讨论】:
-
我认为 AWS 没有“官方”类型,您可能会找到社区类型。另外我认为您正在寻找的是 API Gateway 定义,因为 lambda 可以根据您对它的操作返回您想要的任何内容。
-
True .. IT 更多的是 'api 网关方法响应类型' ;)
标签: typescript aws-lambda aws-api-gateway