通过方法/动词使AWS无服务器函数唯一



我为用户提供了一些CRUD操作。我希望我的URI为/user/{id},并使动词决定使用哪种方法,例如。张贴并放置。在我的云形式模板文件中,我的资源看起来像这样:

    "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"
        }
      }
    }
  }
}

这将给我这个错误:"无法在路径'/user/{id}'中创建资源:该资源的同级({id})已经具有可变路径部分 - 只有一个允许一个"。

可以通过方法/动词使它们独一无二?还是哪种解决方案是最好的..?要拥有/用户/作为我的路径并将我的ID发送到对象中,请使用Querystring或为这样的路径进行"/user/update/fimes/{id}"/user/user/get/get/{id}"?

查看此示例,看起来模板中有一些问题:

  • 确保您的路径参数相同。您正在使用{id}{Id}。看起来像路径参数很敏感,因此您可能只想在两个功能中使用{id}
  • 对于您的GetUser功能,请使用GetResource事件而不是PutResource

希望这会有所帮助!

最新更新