简体   繁体   English

如何指定从步骤 function 调用 lambda function 的方法和路径?

[英]How can I specify method and path for calling lambda function from step function?

I'd like to call lambda function using a state machine with passing path and method (as in usual HTTP sense).我想使用带有传递pathmethod的 state 机器调用 lambda function(与通常的 HTTP 意义一样)。 Current serverless template to achieve that is the following:当前实现的无服务器模板如下:

functions:
  myfunction:
    handler: bin/myfunction
    events:
      - http:
          path: setup
          method: POST

stepFunctions:
  validate: true
  stateMachines:
    myMachine:
      name: myMachine
      definition:
        StartAt: Setup
        States:
          Setup:
            Type: Task
            Resource:
              Fn::GetAtt: [myfunction, Arn]
            Parameters:
              InvocationType: Event
              Payload:
                path: "/setup"
                httpMethod: "POST"
                body: ""
            End: true

However, the actual call that arrives to myfunction is a GET request with path / .但是,到达myfunction的实际调用是路径为/GET请求。 Fields that I used as a payload are from lambda:InvokeFunction API where one can set body , path and httpMethod as a json in Payload property of lambda.InvokeInput and get everything called correctly.我用作有效负载的字段来自lambda:InvokeFunction API,其中可以在 lambda.InvokeInput 的Payload属性中将bodypathhttpMethod设置为lambda.InvokeInput并正确调用所有内容。

How to replicate the same with my example?如何用我的例子复制相同的东西?

path and httpMethod are for invoking an API Gateway route, not a Lambda function . pathhttpMethod用于调用API 网关路由,而不是Lambda function

A Lambda function invocation (mostly) takes a function name, invocation type & a payload.Lambda function 调用(大部分)采用 function 名称、调用类型和有效负载。

If you must go via API Gateway, take a look at the official 'Call API Gateway with Step Functions' guide on how to do this otherwise just invoke your Lambda manually.如果您必须通过 API 网关访问 go,请查看官方“使用 Step Functions 调用 API 网关”指南,了解如何执行此操作,否则只需手动调用您的 Lambda。

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

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