使用无服务器框架配置带有path参数的API路由时出现问题



我对AWS无服务器和无服务器框架比较陌生。我已经创建了以下API路由,并使用离线插件对它们进行了测试,并按预期工作。但是,当我试图使用sls deploy将其部署到我的AWS时,它会向我抛出以下错误:

Error:
CREATE_FAILED: ApiGatewayResourceNoteTimestampVar (AWS::ApiGateway::Resource)
Resource handler returned message: "A sibling ({note_id}) of this resource already has a variable path part -- only one is allowed (Service: ApiGateway, Status Code: 400, Request ID: c12acedd-d270-4988-bb01-427d058aa76c, Extended Request ID: null)" (RequestToken: 803cf4a6-5bc4-48c5-6648-2b0de46528f6, HandlerErrorCode: InvalidRequest)
我的<<p> em> serverless。Yml 看起来像这样
functions:
add-note:
handler: apis/add-note.handler
description: POST /note
events:
- http:
path: note
method: post
cors:
origins: "*"
headers: ${self:custom.allowedHeaders}
update-note:
handler: apis/update-note.handler
description: PATCH /note
events:
- http:
path: note
method: patch
cors:
origins: "*"
headers: ${self:custom.allowedHeaders}
delete-note:
handler: apis/delete-note.handler
description: DELETE /note/{timestamp}
events:
- http:
path: note/{timestamp}
method: delete
cors:
origins: "*"
headers: ${self:custom.allowedHeaders}
get-notes:
handler: apis/get-notes.handler
description: GET /note
events:
- http:
path: note
method: get
cors:
origins: "*"
headers: ${self:custom.allowedHeaders}
get-note:
handler: apis/get-note.handler
description: GET /note/{note_id}
events:
- http:
path: note/{note_id}
method: get
cors:
origins: "*"
headers: ${self:custom.allowedHeaders}

我不知道代码有什么问题,因为它在本地工作得很好?我很感激你的帮助。

如果你要从一个lambda函数更改路由到另一个,就会发生这种情况。这是API Gateway和Lambda交互的结果。

你需要先从函数中移除路由,部署堆栈,然后再将路由添加到新函数中。

它在本地工作,因为你的API网关模拟器实际上并不使用CloudFormation -这是Serverless用来部署你的应用程序。

嗨,也许你需要在serverless .yml上添加路径note_id的参数有些人喜欢这个例子。

request:          
parameters:       
paths: 
note_id: true

最新更新