1

我正在使用 Amazon Transcribe 服务并尝试让 CloudWatch Events 触发一个 Lambda 函数,该函数对我的 API 执行 POST 请求。

这是 Lambda 函数

var querystring = require('querystring');
var http = require('http');

exports.handler = function(event, context) {


    var post_data = querystring.stringify(
        event
    );

    // An object of options to indicate where to post to
    var post_options = {
        host: '193e561e.ngrok.io',
        port: '80',
        path: '/api/lambda',
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Content-Length': Buffer.byteLength(post_data)
        }
    };

    // Set up the request
    var post_req = http.request(post_options, function(res) {
        res.setEncoding('utf8');
        res.on('data', function(chunk) {
            console.log('Response: ' + chunk);
            context.succeed();
        });
        res.on('error', function(e) {
            console.log("Got error: " + e.message);
            context.done(null, 'FAILURE');
        });

    });

    // post the data
    post_req.write(post_data);
    post_req.end();

}

我已将 CloudWatch Events 配置为侦听 Amazon Transcribe 服务,并专门针对更改为COMPLETED或的作业状态FAILED

cloudwatch 事件触发器

然而,令人惊讶的是,在该事件响应中没有提及转录作业名称。

这是一个例子:

'version' => '0',
  'id' => '1fa5cca6-413f-4a0f-0ba2-66efa49c247e',
  'detail-type' => 'Transcribe Job State Change',
  'source' => 'aws.transcribe',
  'account' => '405723091079',
  'time' => '2019-11-19T19:04:25Z',
  'region' => 'eu-west-1',
  'detail' => NULL,

这是我认为我的应用程序在通过 Amazon Transcribe 服务调用转录作业的情况下工作的唯一方法,然后当它完成后,点击我的 API 以更新我的应用程序中的必要模型,但没有获取 Transcribe 作业名称,它赢了不行。

任何建议表示赞赏。

4

1 回答 1

1

根据您更新的问题,我怀疑您的问题实际上在这里:

var post_data = querystring.stringify(
    event
);

Querystring 不支持嵌套对象,例如detailcloudwatch 事件的块。更多信息:

因此,尽管您没有在问题中指出,但我怀疑您显示的是由于此 lambda 帖子而收到的响应,而不是您从 AWS Transcribe 收到的原始响应/事件。

也许代替查询字符串:

var post_data = JSON.stringify(event);
于 2019-11-20T17:19:27.600 回答