Put Lambda Under Existing APIG Resource But Different Method

In the APIG, my path is /users with GET method already created using Cloudformation. In my Serverless, i want to create a new POST method under it. How do i do it?

I already tried below but it does not work.

// function.yml
...
events:
  - http:
      path: /users
      method: post
...

// serverless.yml
restApiId: APIG rest id
restApiRootResourceId: APIG root id
   restApiResources: 
       /users: id of my /users

Serverless Error ---------------------------------------
 
  An error occurred: ApiGatewayResourceGeocode - Resource handler returned message: "Another resource with the same parent already has this name: users (Service: ApiGateway, Status Code: 409, Request ID: 9bb3ae3a-a124-4bac-9b70-529ecb88ce2b) (SDK Attempt Count: 1)" (RequestToken: 27dea297-edcb-e5c8-9a24-e3eedf5f2e24, HandlerErrorCode: AlreadyExists).

There is no direct way to do this. I used resources for this problem. Create the lambda without any triggers and use resources to create new method under existing APIG resource and add permission to lambda.

We have multiple lambdas that we trigger from multiple apis. Each API and lambda are provisioned by different templates and deployed using SAM. We would like to consolidate our APIs for ease of use, but we want to keep the lambdas deployment separated. Can we add resources and methods to an exiting API using different templates? 192.168.100.1 192.168.1.1

1 Like