在两个不同的 lambda 中使用两个不同的嵌套"路径"时,无服务器"冲突异常"



问题

我有两个不同的NodeJ lambdas。两者都包含自己的serverless.yml文件。Lambda将构成同一服务的一部分,因此它们共享相同的基本URL。我已经使用了restApiId&restApiRootResourceId键在serverless.yml文件中实现。

我遇到的问题是,当我尝试部署两个Lambda时,我部署的第二个Lambda返回一个无服务器错误:

[0]  
[0]   An error occurred: ApiGatewayResourceApi - Another resource with the same parent already has this name: api (Service: AmazonApiGateway; Status Code: 409; Error Code: ConflictException; Request ID: 93167f58-5890-4f45-bf02-e036b2c04727; Proxy: null).
[0]  
[0]   Get Support --------------------------------------------
[0]      Docs:          docs.serverless.com
[0]      Bugs:          github.com/serverless/serverless/issues
[0]      Issues:        forum.serverless.com

我想要一个如下设置:

Lambda1:https://some.base.url.from.aws/api/v1/staff/getall-获取Lambda2:https://some.base.url.from.aws/api/v1/staff/insert-后

每个lambda的serverless.yml文件如下所示:

# serverless.yml
service: api-lambda-insert-staff
provider:
name: aws
runtime: nodejs14.x
stage: dev
region: eu-west-1
apiGateway:
restApiId: xxxxxxxxx
restApiRootResourceId: xxxxxxxx
functions:
app:
handler: index.handler
events:
- http:
path: api/v1/staff/insert
method: POST
# serverless.yml
service: api-lambda-getall-staff
provider:
name: aws
runtime: nodejs14.x
stage: dev
region: eu-west-1
apiGateway:
restApiId: xxxxxxx
restApiRootResourceId: xxxxxxxxx
functions:
app:
handler: index.handler
events:
- http:
path: api/v1/staff/getall
method: GET

我尝试过的

我查阅了无服务器文档,发现了一些与我设置相似的示例,所以不太确定出了什么问题。

我已经更改了每个Lambda上的函数名称"app",使其独一无二,但同样的问题。

在目前的困境中,任何帮助都将不胜感激。

谢谢。

原来我需要在serverless.yml:中使用以下内容

restApiResources:
"/api": xxxx 
"/api/v1": xxxx
"/api/v1/staff": xxxx

您可以在AWS控制台的API网关中找到xxxx。

最新更新