【发布时间】:2021-07-02 21:11:36
【问题描述】:
我正在练习 aws lambda 函数和无服务器 yml。我正在使用打字稿和javascript es6。我通过离线插件测试我的无服务器 yml 文件。当我导出 lambda 函数并像这样在无服务器 yml 文件中调用它时:handler: src/handlers/hello.hello,我的 lambda 触发该函数并且它按预期工作。我正在尝试将我的 lambda 函数作为导出默认函数并像这样handler: src/handlers/hello.default 调用它。我收到错误:hello is not a function。我不知道我在导出默认值中做错了什么。
这个逻辑有效
import { APIGatewayEvent } from "aws-lambda";
export async function hello(event: APIGatewayEvent) {
console.log(event);
try {
return {
statusCode: 200,
body: JSON.stringify("hello emmy"),
};
} catch (error) {
return {
statusCode: 500,
body: JSON.stringify(error),
};
}
}
此导出默认值不起作用
import { APIGatewayEvent } from "aws-lambda";
export default async function hello(event: APIGatewayEvent) {
try {
return {
statusCode: 200,
body: JSON.stringify("hello world"),
};
} catch (error) {
return {
statusCode: 500,
body: JSON.stringify(error),
};
}
}
【问题讨论】:
标签: amazon-web-services aws-lambda aws-serverless