Lambda集成与Lambda代理:优缺点 [英] Lambda Integration vs. Lambda Proxy: Pros and Cons

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

问题描述

您认为在Lambda集成中使用带或不带有AWS API Gateway中的代理功能的利弊是什么(更具体地说,当使用无服务器框架时)?这是我到目前为止的想法:

What do you think are the Pros and Cons of using Lambda integration with and without the proxy feature in AWS API Gateway (and more specifically, when using the Serverless framework)? Here's what I think up to now:

Lambda与代理集成

  • 专业版:人们可以快速进行原型设计和编码,而无需担心所有必需的配置细节(并且无需重新发明通用模板映射等一些轮子).
  • 专业版:返回状态代码和自定义标头真的很容易,同时有一种通用的方法可以读取请求的正文,标头,参数.
  • 缺点:一切都在代码中完成,因此自动生成文档会有些困难.依赖关系(标题,模型,返回的状态代码)被隐藏"在代码中.
  • Pro: One can rapidly prototype and code without worrying about all the needed configuration details (and reinventing a few wheels like generic template mappings, etc).
  • Pro: It's really easy to return any status code and custom headers, while at the same time there's a generic way to read the body, headers, parameters, of the request.
  • Con: Everything is done in code, so autogenerating documentation is a bit more difficult. Dependencies (headers, models, returned status codes) are "hidden" in the code.

没有代理的Lambda集成

  • 缺点:需要花费更多的时间来进行设置,并且此配置可能会在不同的资源中重复.
  • 专业版:它允许解耦lambda接收和返回的内容,以及如何将其映射到不同的HTTP状态代码,标头和有效负载.
  • 专业版:非常有用,因为它预先规定了返回的内容以及在标头和有效负载方面的要求.
  • 专业版:从长远来看,设置所有内容时的辛苦工作非常有用,因为一个人可以将所有内容导出到Swagger,因此其他人可以使用它为此生成不同的SDK.
  • Con: Involves a lot more of work to set it up, and this configuration might be duplicated in different resources.
  • Pro: It allows one to decouple what the lambda receives and returns, and how it gets mapped to different HTTP status codes, headers, and payloads.
  • Pro: Very useful because it stipulates upfront what it returns, and what it requires in terms of headers and payloads.
  • Pro: The hard work when setting up everything is useful in the long run because one can export everything to Swagger, so others can use this to generate different SDKs for it.

您有什么想法?您通常使用Lambda代理还是普通的Lambda集成?您更喜欢什么,为什么?

What are your thoughts? Do you generally use Lambda Proxy or plain Lambda integrations? What do you prefer, and why?

编辑:到目前为止,由于提到的原因(去耦和声明依赖项-标头,状态代码等),我倾向于始终选择不使用代理功能.

EDIT: So far, I'm inclined to always choose not to use the proxy features due to the reasons mentioned (decoupling and stating dependencies -headers, status codes, etc- upfront).

推荐答案

它看起来像AWS

It looks like AWS recommends choosing Lambda Proxy Integration for new API development.

注意

Lambda定制集成(以前称为Lambda集成)是一项旧技术.我们建议您对任何新API使用Lambda代理集成.有关更多信息,请参阅使用Lambda代理集成构建API网关API.

The Lambda custom integration, formerly known as the Lambda integration, is a legacy technology. We recommend that you use the Lambda proxy integration for any new API. For more information, see Build an API Gateway API with Lambda Proxy Integration

我知道,使用代理集成而非自定义集成来启动API端点和lambda集成是很快"的事情(短期内),但令我惊讶的是,这是对 all的推荐 API/Lambda开发正在进行:

I understand that it's a lot "quicker" (in the short term) to spin up an API endpoint and lambda integration using proxy integration rather than the custom integration, but I'm surprised that it's the recommendation for all API / Lambda development going forward:

  • 我将API Gateway描绘为负责处理"HTTP详细信息".使用代理集成会(至少是其中的一部分)将这种责任强加给Lambda函数. (即知道如何解释和确定HTTP标头,查询参数,状态码等)
  • 这样做,我觉得这是 muddies 背后的Lambda函数的责任-Lambda现在既要处理被称为要做的任何业务"逻辑,又要处理解释传入HTTP值并确定传出HTTP响应值.
  • 当然,您可以实现一个附加的Lambda函数层来抽象HTTP详细信息,但这不是API Gateway应该做的吗?
  • 除了为HTTP请求提供服务外,它还会降低在上下文 中重用任何给定Lambda函数的能力,除非非HTTP客户端将请求格式化为HTTP请求.
  • I pictured API Gateway as being responsible for handling the "HTTP details". Using Proxy Integration forces (at least a subset of) that responsibility onto the Lambda function. (i.e. knowing how to interpret and decide on HTTP headers, query parameters, status codes, etc.)
  • In doing that, I feel that it muddies the responsibility of the backing Lambda function -- Lambda now needs to both handle whatever "business" logic it's being called to do, and also handle interpreting the incoming HTTP values and decide on the outgoing HTTP response values.
  • Granted, you could implement an additional Lambda function layer to abstract away the HTTP details, but isn't that what API Gateway is supposed to do?
  • It reduces the ability to re-use any given Lambda function in a context other than servicing HTTP requests, unless non-HTTP clients format the request as if it were an HTTP request.

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

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