0

I got some CRUD operations for my user. I want my URI to be /user/{id} and make the VERB decide what method to use, eg. post and put. In my cloudformation template file my resources looks like this:

    "UpdateUser" : {
  "Type" : "AWS::Serverless::Function",
  "Properties": {
    "Handler": "AWSServerless::AWSServerless.UserFunctions::UpdateUserAsync",
    "Runtime": "dotnetcore1.0",
    "CodeUri": "",
    "Description": "Function to update a user",
    "MemorySize": 128,
    "Timeout": 30,
    "Role": null,
    "Policies": [ "AWSLambdaFullAccess" ],
    "Events": {
      "PutResource": {
        "Type": "Api",
        "Properties": {
          "Path": "/user/{id}",
          "Method": "PUT"
        }
      }
    }
  }
},

"GetUser" : {
  "Type" : "AWS::Serverless::Function",
  "Properties": {
    "Handler": "AWSServerless::AWSServerless.UserFunctions::GetUserAsync",
    "Runtime": "dotnetcore1.0",
    "CodeUri": "",
    "Description": "Function to get a single user",
    "MemorySize": 128,
    "Timeout": 30,
    "Role": null,
    "Policies": [ "AWSLambdaFullAccess" ],
    "Events": {
      "PutResource": {
        "Type": "Api",
        "Properties": {
          "Path": "/user/{Id}",
          "Method": "GET"
        }
      }
    }
  }
}

That will give me this error: "Unable to create resource at path '/user/{id}': A sibling ({Id}) of this resource already has a variable path part -- only one is allowed".

Is it possible to make them unique by the Method/Verb? Or what solution is best..? To have /user/ as my path and send my id in the object, use a querystring or make the path to something like this "/user/update/{id}" "/user/get/{id}"?

thatsIT
  • 2,085
  • 6
  • 29
  • 43
  • Are you adding multiple events inside the same `AWS::Serverless::Function` resource, or are these separate `AWS::Serverless::Function` resources? – maafk Dec 19 '17 at 12:47
  • @tkwargs They are separated. I updated my post. – thatsIT Dec 21 '17 at 22:05

1 Answers1

1

Looking at this example, looks there are a few problems in your template:

  • Make sure your path params are the same. You are using {id} and {Id}. It's looking like path params are case sensitive, so you might want to use only {id} in both functions.
  • For your GetUser function, use the GetResource event instead of PutResource

Hope this helps!

spg
  • 9,309
  • 4
  • 36
  • 41