CloudWatch Events 在 Amazon Transcribe 事件上触发

CloudWatch Events trigger on Amazon Transcribe event

我正在使用 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 服务,并专门侦听更改为 COMPLETEDFAILED 的作业状态。

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

这是一个例子:

'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 以更新我的应用程序中的必要模型,但是没有获取转录作业名称,它将无法工作。

感谢任何建议。

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

var post_data = querystring.stringify(
    event
);

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

所以虽然你没有在你的问题中指出它,但我怀疑你正在显示你收到的响应作为这个 lambda post 的结果,而不是原始 response/event 你是从 AWS Transcribe 接收。

也许代替查询字符串:

var post_data = JSON.stringify(event);