用于创建EMR群集的Lambda不会触发群集创建

Die*_*ães 9 amazon-web-services node.js emr gruntjs aws-lambda

我正在尝试运行一个创建集群的λ代码,但没有任何反应,也许我误解了Node上的用法(因为我对它并不熟悉).

功能很简单:

// 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');
};
Run Code Online (Sandbox Code Playgroud)

我正在使用grunt-aws-lambdagrunt任务和控制台测试它,但除了:

aws-emr-lambda$ grunt lambda_invoke
Running "lambda_invoke:default" (lambda_invoke) task

Message
-------
? Completed

Done, without errors.
Run Code Online (Sandbox Code Playgroud)

从AWS控制台执行它会产生相同的输出,并且不会创建EMR群集.

有什么想法吗?

Dar*_*con 10

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');
        });
};
Run Code Online (Sandbox Code Playgroud)

  • 大!通过该编辑我现在能够通过请求看到validationError,非常感谢! (2认同)