我正在尝试从AWS Lambda连接到Internet,我有一个带NAT网关的私有子网,但该功能仍无法连接到Internet ...
因此,我尝试使用我的AWS Lambda函数访问互联网。我已经尝试过Java和NodeJS 4,但都没有碰运气。
我有一个带有子网的私有VPC:10.0.10.0/24
如您所见,我已经在NAT网关中添加了一条规则:
我将AWS Lambda配置如下:
选择该子网(10.0.10.0)并使用对所有内容(入站和出站)都开放的安全组
但是,当我尝试从Internet下载某些内容时,lambda超时了:
'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 …Run Code Online (Sandbox Code Playgroud)