我正在编写一个lambda函数来尝试连接到在给定OpsWorks层下运行的所有实例上的端点。我的问题是,当我尝试测试它时,函数会超时。输出中没有列出其他错误,因此我不确定从哪里开始调试此问题。
我发现了this StackOverflow问题,我尝试在没有VPC的情况下创建该函数,但问题依然存在(有问题的OpsWorks堆栈是在VPC背后)。
有问题的lambda代码是:
exports.handler = function(event, context) {
var done = false;
var awsOptions = {
region: 'us-east-1'
};
var AWS = require('aws-sdk');
var opsWorks = new AWS.OpsWorks(awsOptions);
var appIds = ["MY_APP_ID"];
var layerIds = ["MY_LAYER_ID"];
var stackId = "MY_STACK"
var isOnline = function(instance) {
return instance.Status == 'online';
}
console.log("Have all the variables set up, time to run...");
opsWorks.describeLayers({StackId: stackId, LayerIds: layerIds},
function(error, layers) {
console.log("Described the layer...");
console.log(layers);
opsWorks.describeInstances({LayerId: layers[0].LayerId},
function(err, instances) {
console.log("Described the instances on the layer");
if (err) {
console.error("No instances found!");
}
console.log("No errors, keep going...");
instances.Instances.filter(isOnline).forEach(function(instance) {
console.log("Filtered out the offline instances.");
var options = {
method: "GET",
path: "/endpoint",
port: 123,
timeout: 10000,
url: instance.Hostname
};
http.request(options, function(response) {
if (response.statusCode != 200) {
console.error("Instance " + instance.InstanceId
+ " is not responding!");
} else {
console.log("Got a response, time to do stuff!");
}
});
});
done = true;
});
});
while (!done) {
// Keep waiting...
}
};
答案 0 :(得分:0)
埃里克,
我通过两种方式解决了我面临的类似问题:
希望它有所帮助!