gpt4 book ai didi

javascript - 无服务器:此服务中不存在该功能

转载 作者:行者123 更新时间:2023-11-28 13:00:30 25 4
gpt4 key购买 nike

在无服务器中,我的函数具有以下目录结构:

serverless.yml
functions -
stories -
create.js
get.js

我的serverless.yml看起来像这样:

functions:
stories:
create:
handler: functions/stories/create.main
events:
- http:
path: stories/create
method: post
cors: true
authorizer: aws_iam
get:
handler: functions/stories/get.main
events:
- http:
path: stories/{id}
method: get
cors: true
authorizer: aws_iam

但是,当我运行测试来检查创建时:serverless invoke local --function create --path mocks/create-event.json 我收到以下错误:

Serverless Error ---------------------------------------

Function "create" doesn't exist in this Service

我设法让一个函数正常工作,如下所示:

functions:
stories:
handler: functions/stories/create.main
events:
- http:
path: stories/create
method: post
cors: true
authorizer: aws_iam

自从我添加了 get 函数后,我决定需要在故事之后添加 create 和 get 部分,但无论我如何更改处理程序,这些函数似乎都不存在。

我尝试将路径更改为functions/stories/create/create.main,没有任何区别,是否有任何明显的我遗漏的内容以允许同一位置内有多个处理程序?

我正在查看以下内容example ,它使用一个包含多个功能的“todos”文件夹,但我看不出它和我的有任何明显的区别,除了我添加了一个额外的文件夹。

最佳答案

您的模板无效。您不能只是将函数放在任意节点下来告诉框架它适用于应用程序的某些对象。您的 stories: 节点应该是注释。

尝试这样的事情:

functions:
# Stories related functions
createStory:
handler: functions/stories/create.main
events:
- http:
path: stories # You can post directly to stories to be more RESTful
method: post
cors: true
authorizer: aws_iam
getStory:
handler: functions/stories/get.main
events:
- http:
path: stories/{id}
method: get
cors: true
authorizer: aws_iam

# More examples to understand the routing
getAllStories:
handler: functions/stories/getAll.main # Returns a list of all stories
events:
- http:
path: stories
method: get
cors: true
authorizer: aws_iam
deleteStory:
handler: functions/stories/delete.main # Deletes a story
events:
- http:
path: stories/{id}
method: delete
cors: true
authorizer: aws_iam

关于javascript - 无服务器:此服务中不存在该功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51014209/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com