简体   繁体   English

如何在AWS CloudFormation中添加参数的接受

[英]How to add the taking of a parameter in AWS CloudFormation

I am using an AWS Serverless Function to create API events. 我正在使用AWS无服务器功能创建API事件。 Currently I am working on my GET event and it works the way I want it to with the given URL from AWS. 目前,我正在处理GET事件,并且可以通过AWS中的给定URL进行操作。 I want to be able to put a / and then a number and be able to get this number. 我希望能够先输入一个/,然后再输入一个数字,并能够获取该数字。 For example, it would be myurl/1 . 例如,它将为myurl/1 That number would be used to get a specific id versus the original function which gets all ID's. 该数字将用于获取特定ID,而原始函数将获取所有ID。 I am using a CloudFormation template so it needs to be something I put into the template. 我正在使用CloudFormation模板,因此它必须是我放入模板中的东西。 The event section currently looks like: 事件部分当前看起来像:

Events:
    GetEvent:
      Type: Api
      Properties:
        Path: /
        Method: get

I need to know where to add a section to be able to accept a number at the end of the path so that I can use it in my code. 我需要知道在路径末尾添加节的位置,以便可以在代码中使用它。

You can add the event as follows 您可以如下添加事件

functions
  get:
      handler: myurl/get.get
      events:
        - http:
            path: myurl/{id}
            method: get
            cors: true

Note that above is not a part of CloudFormation resources section in serverless.yml. 请注意,以上内容不是serverless.yml中CloudFormation 资源部分的一部分。

Inside your event handler code in Lambda, you should be able to access the id parameter using the event object as follows 在Lambda的事件处理程序代码中,您应该能够使用事件对象访问id参数,如下所示

event.pathParameters.id

Refer this Serverless example for more details. 请参阅有关详细信息,无服务器的例子。

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

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