简体   繁体   English

使用动态路径创建AWS Lambda函数

[英]Create aws lambda function with dynamic path

I'm creating an aws lambda function using VS Code aws plugin, the language is nodeJS. 我正在使用VS Code aws插件创建aws lambda函数,语言是nodeJS。

I need to pass a dynamic id in the request preferably as part of the path. 我需要在请求中传递动态ID,最好将其作为路径的一部分。

In nodeJS express I would do it something like this 在nodeJS express中,我会这样做

/api/route/:id

However when I try to do this in my lambda function's template.yaml like this 但是,当我尝试在我的lambda函数的template.yaml这样做时

Events:
    HelloWorld:
      Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
      Properties:
      //***** this line
        Path: /api/route/:id
        Method: get

It does'n work 没用

Any help would be appreciated 任何帮助,将不胜感激

PS I'm able to pass it as a query param like so PS我能够像这样传递它作为查询参数

https://awslambdafunction.com/api/route/?id=1234

It does work but I would really like to have it as part of the path itself like this 它确实有效,但是我真的很想像这样将它作为路径本身的一部分

https://awslambdafunction.com/api/route/1234    

Shmili, Shmili,

I'm not sure if it'll work with AWS VS Code plugin. 我不确定它是否可以与AWS VS Code插件一起使用。 But I did it like this using Serverless Framework: 但是我使用Serverless Framework做到了这一点:

functions:
  updateBook:
    handler: handler.updateBook
    events:
      - http:
          path: /book/{id}
          method: put
          private: true

It may put you on a right direction. 它可能使您朝着正确的方向前进。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM