Serverless 'ConflictException' when using two different nested 'paths' in two different lambdas

The Problem

I have two different NodeJs lambdas. Both contain their own serverless.yml file. The lambdas will form part of the same service so they share the same base URL. I’ve made use of the restApiId & restApiRootResourceId keys in the serverless.yml file to achieve this.

The problem I have is, when I try to deploy both lambdas, the second one I deploy returns a serverless error:

[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

I want a set up like follows:

Lambda1: https://some.base.url.from.aws/api/v1/staff/getall - GET Lambda2: https://some.base.url.from.aws/api/v1/staff/insert - POST

My serverless.yml file for each lambda is as follows:

# 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

what I’ve tried

I’ve looked through serverless documentation, and found a few examples which have a similar set up to me, so not quite sure what’s going wrong.

I’ve changed the function name ‘app’ on each Lambda to make them unique, but again, same problem.

At a loose end now, any help, is much appreciated.

Thanks.

1 Like