使用Lambda代理集成与Lambda配合使用Step Function [英] Step Functions with Lambdas using Lambda Proxy Integration

查看:338
本文介绍了使用Lambda代理集成与Lambda配合使用Step Function的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了许多Lambda函数,这些函数通过API网关作为Rest端点公开.我选择了"Lambda代理集成",因为它似乎是一种入门的直接方法.

I have written a bunch of Lambda functions that are exposed as Rest endpoints through API Gateway. I have chosen the "Lambda Proxy Integration" since it seemed like a straightforward way to get started.

现在,我想通过AWS Step Functions将这些功能中的2个链接在一起.除了如何为每个任务创建适当的输入之外,常规的集成和配置都可以正常工作.

Now I want to chain together 2 of these functions via AWS Step Functions. The general integration and configuration works fine except how to create the proper inputs for each task.

使用控制台,我可以启动执行并提供以下JSON:

Using the console I can start an Execution and give the following JSON:

{
    "headers": {
        "Authorization": "Bearer 12345"
    },
    "body": "\"some\": \"json\"",
    "queryParameters: {
        "more": "here"
    }
}

这是我Lambda函数的输入的样子,因为我在各处都使用Lambda代理集成.

This is how the inputs to my Lambda functions look like since I'm using the Lambda Proxy Integration everywhere.

输出看起来像这样:

{
  "isBase64Encoded": false,
  "statusCode": 200,
  "headers": {
    "Access-Control-Allow-Origin": "*"
  },
  "body": "{\"message\":\"Great\"}"
}

这也是很好的独立工具,API网关将这些信息映射回正确的HTTP返回代码和响应以及所有信息.

This is also fine stand-alone, API Gateway maps these infos back to proper HTTP return codes and responses and all.

现在:使用步函数"时如何创建这些输入JSON.当然,使用控制台很容易就可以进行第一个输入.但是,如何创建下一个输入并混入上一个输出的一部分中?要点中的一些问题:

Now: how do I create these input JSONs when using Step Functions. The very first input is easy using the console, of course. But how do I create the next input and mix in a part of the previous output? Some of the problems in bullet points:

  • 使用InputPath,ResultPath和OutputPath我似乎只能将上一步的整个"输出用作输入,或者将一部分用作下一步的输入.但是我不能只使用输出的一部分,就我而言,是响应的元素"body".
  • 无论如何,此元素"body"都已转义,所以我想在以某种方式将其用于下一个输入之前需要取消转义吗?但是如何?
  • 输入JSON需要由诸如标头",正文"或"queryParameters"之类的元素组成,而这些元素根本不会出现在上一个输出中.我该如何创建这些东西?

我想知道Step Functions是否真的不能与为Lambda代理集成构建的Lambda一起使用.是这样吗人们如何在不遇到这些问题的情况下使用步进功能?

I'm wondering whether Step Functions just don't really work with Lambdas built for the Lambda Proxy Integration. Is that the case? How are people using Step Functions without running into these problems?

推荐答案

Step函数被设计为直接与lambda集成,而不是通过api网关进行集成,这就是Step函数不处理它的原因,这自然使Jain逃脱了.

Step function is designed to integrate directly with lambda and not via api gateway, that’s the reason why step functions doesn’t handle it escaped Jain naturally.

如果您想同时通过api网关和step函数访问lambda代码,我建议您执行以下操作: 将lambda代码逻辑分为两部分,即核心逻辑和核心逻辑的包装程序,它们基本上执行从主体中提取字段并对其进行转义的功能.这样,您的api网关可以调用包装器lambda,而step函数可以调用核心逻辑lambda.通过这种设计,您将能够实现自己的目标.此外,您可以将lambda定义为一个cfn和代码包的一部分,这将有助于轻松维护.

If you want to have your lambda code accessible via both api gateway and step function, I would recommend following: Split the lambda code logic into 2 parts I.e. core logic and the wrapper over core logic that basically performs the functionality of extracting out the fields from body and unescaping it. This way your api gateway can invoke the wrapper lambda and you step function can invoke the core logic lambda. With this design you would be able to achieve your goal. Moreover, you can define the lambdas as part of one cfn and code package which will help in easy maintenance.

我希望这能回答您的问题.

I hope this answers your questions.

谢谢

这篇关于使用Lambda代理集成与Lambda配合使用Step Function的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆