'Issue while configuring API routes with path parameter using serverless framework
I'm relatively new to the AWS serverless and serverless framework. I have created the following API routes and tested them using the offline plugin and it is working as expected. But when I'm trying to deploy this using sls deploy to my AWS it is throwing me the following error.
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)
My serverless.yml look likes this
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}
I don't know what's wrong with the code as it is working well locally? I'd appreciated a help here.
Solution 1:[1]
This can happen if you're changing a route from one lambda function to another. It's a consequence of how API Gateway and Lambda interact.
You'll need to first remove the route from the function, deploy the stack, and then add the route to the new function.
It works locally because your API Gateway emulator doesn't actually use CloudFormation - which is what Serverless uses to deploy your application.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Aaron Stuyvenberg |
