随机状态码:连接到Lambda的AWS api网关上的502错误 [英] Random status code: 502 errors on AWS api gateway connected to lambda

查看:139
本文介绍了随机状态码:连接到Lambda的AWS api网关上的502错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用代理集成通过api网关公开了多个lambda.我会不时收到状态码502的奇怪错误. lambda云监视日志中没有任何内容.我在下面发布了示例请求的api网关日志:

I have multiple lambdas exposed with api gateway using proxy integration. From time to time i'm getting strange errors with status code 502. There is nothing in lambda cloud watch logs. Below i posted api gateway logs for sample request:

(0cbbd9f5-f1bd-11e7-92c0-4d5d3b7d0380) Received response. Integration latency: 231 ms

(0cbbd9f5-f1bd-11e7-92c0-4d5d3b7d0380) Endpoint response body before transformations:
{
    "Message": "An error occurred and the request cannot be processed.",
    "Type": "Service"
}

(0cbbd9f5-f1bd-11e7-92c0-4d5d3b7d0380) Endpoint response headers: 
{
    Connection=keep-alive, 
    x-amzn-RequestId=0cbc9dee-f1bd-11e7-857b-91f7f814692c, 
    x-amzn-ErrorType=ServiceException, 
    Content-Length=86, 
    Date=Fri, 05 Jan 2018 02:06:32 GMT, 
    Content-Type=application/json
}

(0cbbd9f5-f1bd-11e7-92c0-4d5d3b7d0380) Execution failed due to configuration error: Malformed Lambda proxy response

(0cbbd9f5-f1bd-11e7-92c0-4d5d3b7d0380) Method completed with status: 502

基本上看来,api网关无法到达lambda,并且对lambda的调用正在返回:

Basically it seems that api gateway cannot reach lambda and call to lambda is returning:

(0cbbd9f5-f1bd-11e7-92c0-4d5d3b7d0380) Endpoint response body before transformations:
{
    "Message": "An error occurred and the request cannot be processed.",
    "Type": "Service"
}

还有其他人遇到这些问题吗?就我而言,唯一可能的解决方法是编写重试机制,但就我而言,这似乎是我缺少某些配置,否则它们应该处理AWS失败.

Is there any one else experiencing those issues? Only possible fix from my side is to write retry mechanism but from my side it looks rather that i am missing some configuration or it's AWS failure which they should handle.

推荐答案

我在这里列出了一种可能的原因...

I'm listing here one possible reason...

将AWS Lambda配置为在VPC中运行. VPC每次执行需要一个IP.

When an AWS Lambda is configured to run in VPC. It takes one IP per execution from VPC.

如果VPC没有太多的免费IP,那么您的lambda将会无声地失败:(

And if VPC doesn't much free IPs then your lambda will fail silently :(

我个人已经遇到了有关有限IP的问题,增加IP解决了这个问题.

I've personally faced issues in regards to limited IP, increasing the IPs solved the issue.

链接

您指定的子网应具有足够的可用IP地址 以匹配ENI的数量.

The subnets you specify should have sufficient available IP addresses to match the number of ENIs.

我们还建议您在每个子网中至少指定一个子网 Lambda函数配置中的可用区.通过指定 每个可用区中的子网,您的Lambda函数可以 如果发生故障或IP用尽,则在另一个可用区中运行 地址.

We also recommend that you specify at least one subnet in each Availability Zone in your Lambda function configuration. By specifying subnets in each of the Availability Zones, your Lambda function can run in another Availability Zone if one goes down or runs out of IP addresses.

注意

如果您的VPC没有足够的ENI或子网IP,则您的Lambda 功能不会随着请求的增加而扩展,您将看到一个 功能故障增加. AWS Lambda当前未登录 由ENI或IP不足引起的CloudWatch Logs错误 地址..如果您发现错误增加而没有相应的地址 CloudWatch Logs,您可以同步调用Lambda函数以 获取错误响应(例如,在 AWS Lambda控制台,因为该控制台调用您的Lambda函数 同步并显示错误).

If your VPC does not have sufficient ENIs or subnet IPs, your Lambda function will not scale as requests increase, and you will see an increase in function failures. AWS Lambda currently does not log errors to CloudWatch Logs that are caused by insufficient ENIs or IP addresses. If you see an increase in errors without corresponding CloudWatch Logs, you can invoke the Lambda function synchronously to get the error responses (for example, test your Lambda function in the AWS Lambda console because the console invokes your Lambda function synchronously and displays errors).

这篇关于随机状态码:连接到Lambda的AWS api网关上的502错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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