I'm trying to run a λ code that creates a cluster, but nothing happens, maybe I'm misunderstanding the usage on Node (since I'm not that familiar with it.)
我正在尝试运行一个创建集群的λ代码,但没有任何反应,也许我误解了Node上的用法(因为我对它并不熟悉)。
The function is as simple as:
功能如下:
// configure AWS Dependecies
var AWS = require('aws-sdk');
exports.handler = function(event, context) {
// EMR Client
var emr = new AWS.EMR({apiVersion: '2009-03-31', region: 'us-east-1'});
var params = {... dozens of params describing jobs ...};
var AWSRequest = emr.runJobFlow(params);
AWSRequest
.on('success', function(response){ console.log("success => " + response)})
.on('error', function(response){ console.log("error => " + response)})
.on('complete', function(response){ console.log("complete => " + response)})
.send( function(err, data){
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
context.done(null, 'λ Completed');
};
I'm testing it with the grunt-aws-lambda
grunt task and in the console, but nothing shows except for:
我正在使用grunt-aws-lambda grunt任务和控制台测试它,但除了:
aws-emr-lambda$ grunt lambda_invoke
Running "lambda_invoke:default" (lambda_invoke) task
Message
-------
λ Completed
Done, without errors.
Executing it from the AWS console results in the same output and no EMR Cluster is created.
从AWS控制台执行它会产生相同的输出,并且不会创建EMR群集。
Any thoughts on this?
有什么想法吗?
1 个解决方案
#1
9
AWSRequest
sends requests asynchronously, but you are calling context.done
in your main handler. This means that at best this is going to send the request but not wait for a response. context.done
needs to be in the send
callback or AWS will likely terminate the function before the response is received, or perhaps even before it is sent, depending on how the request is performed within the AWS SDK.
AWSRequest以异步方式发送请求,但您在主处理程序中调用context.done。这意味着最好这将发送请求但不等待响应。 context.done需要位于send回调中,或者AWS可能会在收到响应之前终止该函数,或者甚至可能在发送之前终止该函数,具体取决于在AWS SDK中执行请求的方式。
exports.handler = function(event, context) {
// EMR Client
var emr = new AWS.EMR({apiVersion:'2009-03-31', region:'us-east-1'});
var params = {... dozens of params describing jobs ...};
var AWSRequest = emr.runJobFlow(params);
AWSRequest
.on('success', function(response){ console.log("success => " + response)})
.on('error', function(response){ console.log("error => " + response)})
.on('complete', function(response){ console.log("complete => " + response)})
.send( function(err, data){
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
context.done(null,'λ Completed');
});
};
#1
9
AWSRequest
sends requests asynchronously, but you are calling context.done
in your main handler. This means that at best this is going to send the request but not wait for a response. context.done
needs to be in the send
callback or AWS will likely terminate the function before the response is received, or perhaps even before it is sent, depending on how the request is performed within the AWS SDK.
AWSRequest以异步方式发送请求,但您在主处理程序中调用context.done。这意味着最好这将发送请求但不等待响应。 context.done需要位于send回调中,或者AWS可能会在收到响应之前终止该函数,或者甚至可能在发送之前终止该函数,具体取决于在AWS SDK中执行请求的方式。
exports.handler = function(event, context) {
// EMR Client
var emr = new AWS.EMR({apiVersion:'2009-03-31', region:'us-east-1'});
var params = {... dozens of params describing jobs ...};
var AWSRequest = emr.runJobFlow(params);
AWSRequest
.on('success', function(response){ console.log("success => " + response)})
.on('error', function(response){ console.log("error => " + response)})
.on('complete', function(response){ console.log("complete => " + response)})
.send( function(err, data){
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
context.done(null,'λ Completed');
});
};