我正在尝试从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) 我使用 Lambda 到 Firebase 消息。我参考这个。但 lambda 函数仍然超时,因为它无法连接到谷歌服务器。
处理程序.js
/ [START imports]
const firebase = require('firebase-admin');
const serviceAccount = require("../serviceAccount.json");
module.exports.message = (event, context, callback) => {
context.callbackWaitsForEmptyEventLoop = false;
const registrationToken = "xxxxxxx";
const payload = {
data: {
score: "850",
time: "2:45"
}
};
// [START initialize]
if(firebase.apps.length == 0) { // <---Important!!! In lambda, it will cause double initialization.
firebase.initializeApp({
credential: firebase.credential.cert(serviceAccount),
databaseURL: 'https://messaging-xxxxx.firebaseio.com'
});
}
// Send a message to the device corresponding to the …Run Code Online (Sandbox Code Playgroud) amazon-web-services firebase aws-lambda firebase-cloud-messaging firebase-admin