AWS Lambda连接到Internet [英] AWS Lambda connecting to Internet
问题描述
我正在尝试从AWS Lambda连接到互联网,我有一个带有NAT网关的私有子网,但该功能仍然无法连接到互联网。 ..
I am trying to connect to internet from AWS Lambda, I have a private subnet with a NAT Gateway but still the function cannot connect to internet...
所以我尝试使用我的AWS Lambda函数访问互联网。我已经尝试了Java和NodeJS 4而没有运气。
So I am trying to access internet with my AWS Lambda function. I have tried both Java and NodeJS 4 with no luck.
我有一个带子网的私有VPC:10.0.10.0/24
I have a private VPC with a subnet: 10.0.10.0/24
如您所见,我已将规则添加到我的NAT网关:
As you can see I have added a rule to my NAT Gateway:
我将AWS Lambda配置为:
I configured my AWS Lambda like this:
选择该子网(10.0.10.0)并使用对所有事物都开放的安全组(入站和出站)
Selecting that subnet (10.0.10.0) and with a security group that is open to everything (both inbound and outbound)
但是当我尝试从互联网上下载内容时,lambda次out:
But yet when I try to download something from internet, the lambda times out:
'use strict';
console.log('Loading function');
var http = require("http");
exports.handler = (event, context, callback) => {
//console.log('Received event:', JSON.stringify(event, null, 2));
console.log('value1 =', event.key1);
console.log('value2 =', event.key2);
console.log('value3 =', event.key3);
var options = {
host: 'www.virgilio.it',
port: 80,
path: '/'
};
http.get(options, function(res) {
console.log("Got response: " + res.statusCode);
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
callback(null, event.key1); // Echo back the first key value
// callback('Something went wrong');
};
{
errorMessage:2016-05- 10T10:11:46.936Z 79968883-1697-11e6-9e17-1f46a366f324任务在55.00
秒后超时
}
{ "errorMessage": "2016-05-10T10:11:46.936Z 79968883-1697-11e6-9e17-1f46a366f324 Task timed out after 55.00 seconds" }
这是一个错误吗?
注意:相同的功能有效如果我没有选择我的VPC
推荐答案
我发现错误,应该将NAT网关添加到公有子网(不是私有子网)。
A公有子网是与 0.0.0.0/0相关联的Internet Gatway路由的子网
I found the error, the NAT Gateway should be added to a public subnet (not a private one).
A public subnet is the subnet with the Internet Gatway route associated to 0.0.0.0/0
这篇关于AWS Lambda连接到Internet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!