Serverless: Cannot have multiple functions targeting the same path with different methods

Created on 20 Aug 2016  ·  3Comments  ·  Source: serverless/serverless

Serverless Framework Version:

1.0.0-beta.2

Operating System:

OSX 10.11.6

Expected Behavior:

Have the following configuration, one method GET user/profile another POST user/profile and receive an error on deployment.

functions:
  getProfile:
    handler: handler.getProfile
    events:
      - http:
          path: user/profile
          method: get
  updateProfile:
    handler: handler.updateProfile
    events:
      - http:
          path: user/profile
          method: post
Actual Behavior:
$ sls deploy
Serverless: Zipping service...
Serverless: Removing old service versions...
Serverless: Uploading .zip file to S3...
Serverless: Updating Stack...
Serverless: Checking stack update progress...
.. 
  Serverless Error ---------------------------------------

     An error occurred while provisioning your cloudformation:
     The following resource(s) failed to create: [ResourceApigEventGetprofileUserProfile].

Most helpful comment

Wait no! Cancel this! It's just a bit of a poorly phrased error! Future people! Here was my problem:

http://forum.serverless.com/t/deployment-error-a-sibling-did-of-this-resource-already-has-a-variable-path-part-only-one-is-allowed/795

So essentially, I had two functions as down below, with two paths like this:

          path: tasks/{taskId}
          path: tasks/{taskToUpdate}

And both paths needed the same key, so I should have used {taskId} both times!

The only request I have for a developer seeing this is maybe to give a better error message than the one AWS gives.

functions:

  updateTask:
    handler: lib/endpoints.createTask
    events:
      - http:
          path: tasks/{taskToUpdate}
          method: put
          cors: true

  deleteTask:
    handler: lib/endpoints.deleteTask
    events:
      - http:
          path: tasks/{taskId}
          method: delete
          cors: true

All 3 comments

This also resolved itself by re-creating the stack. #1908

I have this error too. When I run "serverless remove", then "serverless deploy -v" though, it didn't resolve the issue. This is a problem since I have a normal API that follows the CRUD standard format (like django-rest-framework, or AngularJS Resource. I want to have URLs like:

POST    http://blahblah/task/            # Creates a new task
GET     http://blahblah/task/            # Gets all tasks
GET     http://blahblah/task/{taskId}    # Gets a specific task
PUT     http://blahblah/task/{taskId}    # Updates a specific task
DELETE  http://blahblah/task/{taskId}    # Deletes a specific task

I'm fine with doing exotic things to achieve this, I just want this URL format.

Here is the error I get:

Serverless: Deployment failed!

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

     An error occurred while provisioning your stack: ApiGatewayResourceTasksParenttaskidVar
     - A sibling ({taskId}) of this resource already has
     a variable path part -- only one is allowed.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues

  Your Environment Information -----------------------------
     OS:                 win32
     Node Version:       7.0.0
     Serverless Version: 1.7.0

Wait no! Cancel this! It's just a bit of a poorly phrased error! Future people! Here was my problem:

http://forum.serverless.com/t/deployment-error-a-sibling-did-of-this-resource-already-has-a-variable-path-part-only-one-is-allowed/795

So essentially, I had two functions as down below, with two paths like this:

          path: tasks/{taskId}
          path: tasks/{taskToUpdate}

And both paths needed the same key, so I should have used {taskId} both times!

The only request I have for a developer seeing this is maybe to give a better error message than the one AWS gives.

functions:

  updateTask:
    handler: lib/endpoints.createTask
    events:
      - http:
          path: tasks/{taskToUpdate}
          method: put
          cors: true

  deleteTask:
    handler: lib/endpoints.deleteTask
    events:
      - http:
          path: tasks/{taskId}
          method: delete
          cors: true
Was this page helpful?
0 / 5 - 0 ratings

Related issues

chris-hailstorm picture chris-hailstorm  ·  3Comments

BarakChamo picture BarakChamo  ·  3Comments

cspeer picture cspeer  ·  3Comments

rdehnhardt picture rdehnhardt  ·  3Comments

arabold picture arabold  ·  3Comments