AWS Lambda中的Python请求超时 [英] Python request in AWS Lambda timing out

查看:77
本文介绍了AWS Lambda中的Python请求超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的AWS Lambda发出http请求,但是超时.

I'm trying to make a http request from my AWS Lambda but it times out.

我的代码与此类似:

import requests

def lambda_handler(event, context):
    print('Im making the request')
    request.get('http://www.google.com')
    print('I recieved the response')

但是当我对此进行测试时,我会超时.

But when I test this, I get a timeout.

输出为

Im making the request
END RequestId: id
REPORT RequestId: id    Duration: 15003.25 ms   Billed Duration: 15000 ms   Memory Size: 128 MB Max Memory Used: 18 MB  
2016-04-08T20:33:49.951Z id Task timed out after 15.00 seconds

所以我知道问题不是它没有找到请求包,而是正在运行我的python代码.我只是想知道为什么它在该请求上超时.

So I know the issue isn't it not finding the request package, and it's running my python code. I just figure out why it times out on that request.

推荐答案

我遇到相同的

I encounter same timeout problem, the reason is below.

AWS文档:

将VPC配置添加到Lambda函数时,它只能访问该VPC中的资源.如果Lambda功能需要同时访问VPC资源和公共Internet,则VPC需要在VPC内部具有一个网络地址转换(NAT)实例.

When you add VPC configuration to a Lambda function, it can only access resources in that VPC. If a Lambda function needs to access both VPC resources and the public Internet, the VPC needs to have a Network Address Translation (NAT) instance inside the VPC.

设置VPC时可能会出现一些错误. 我建议您可以遵循博客以构建NAT.

Maybe there are some error when you setting your VPC. I advice you can follow this blog to build NAT.

这篇关于AWS Lambda中的Python请求超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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