Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda Rest API: A sibling ({id}) of this resource already has a variable path part -- only one is allowed Unable to create resource at path

I'm particular new to Lambda and to AWS in general. I'm trying to setup a simple REST API Service with Lambda. I've used CloudFormat and CodePipeline to have a simple Express app. I'm trying to figure out why during the deployment phase, during ExecuteChangeSet I have this error:

Errors found during import: Unable to create resource at path '/stations/{stationId}/allowedUsers': A sibling ({id}) of this resource already has a variable path part -- only one is allowed Unable to create resource at path '/stations/{stationId}/allowedUsers/{userId}': A sibling ({id}) of this resource already has a variable path part -- only one is allowed

This is what I have inside the template.yml

      Events:
      AllowedUsers:
        Type: Api
        Properties:
          Path: /stations/{stationId}/allowedUsers
          Method: get
      AddAllowedUsers:
        Type: Api
        Properties:
          Path: /stations/{stationId}/allowedUsers
          Method: post    
      DeleteAllowedUsers:
        Type: Api
        Properties:
          Path: /stations/{stationId}/allowedUsers/{userId}
          Method: delete
      GetAllowedUser:
        Type: Api
        Properties:
          Path: /stations/{stationId}/allowedUsers/{userId}
          Method: get

I searched a bit for this error but I'm not sure how to solve it.

like image 854
sgrumo Avatar asked Jun 12 '20 14:06

sgrumo


People also ask

How do I pass AWS API gateway request body?

In the Mapping Templates area, choose an option for Request body passthrough to configure how the method request body of an unmapped content type will be passed through the integration request without transformation to the Lambda function, HTTP proxy, or AWS service proxy.

What is resource path in API gateway?

The resource is the API resource you defined in the API gateway. For example in your case /{proxy+} . The path is the actual path from the request.

How to create resources in API Gateway?

Search for API Gateway, click Create API . In the next screen select REST API and select 'Build'. Then, in the Action dropdown, we'll select “Create Resource”—a pane will come up titled “New Child Resource”. Fill the 'resource name' with a name (the path will auto-generate).

What is options in API gateway?

Used by callers to get information about available communication options for the target service.


1 Answers

For me, the issue was different from what is described in the GitHub issue Bryan mentioned.

I was using two different parameter names. Finishing the refactoring and using a single id name fixed the issue.

Example:

DeleteAllowedUsers:
  Type: Api
    Properties:
      Path: /stations/{stationId}/allowedUsers/{id}
      Method: delete
GetAllowedUser:
  Type: Api
    Properties:
      Path: /stations/{stationId}/allowedUsers/{userId}
      Method: get
like image 57
Owen Avatar answered Sep 22 '22 20:09

Owen