CloudWatch Events在Amazon Transcribe事件上触发 [英] CloudWatch Events trigger on Amazon Transcribe event

查看:202
本文介绍了CloudWatch Events在Amazon Transcribe事件上触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm working with the Amazon Transcribe service and trying to get CloudWatch Events to fire a Lambda function that executes a POST request to my API.

这里是Lambda函数

Here's the Lambda function

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服务,特别是针对更改为已完成失败的工作状态。

I've configured CloudWatch Events to listen to the Amazon Transcribe service and specifically for the status of a job changing to COMPLETED or FAILED.

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

What's surprising however is that there's no mention of the Transcribe job name in that event response.

这里是一个例子:

'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职位名称,它将无法正常工作。

This is the only way I can think of my app working where the transcription job is invoked via the Amazon Transcribe service and then when it's done, hit my API to update the necessary models in my app but without getting the Transcribe job name, it won't work.

推荐答案

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

Per your updated question, I suspect your issue is actually here:

var post_data = querystring.stringify(
    event
);

查询字符串不支持嵌套对象,例如细节 cloudwatch事件的块。更多信息:

Querystring does not support nested objects, such as the detail block of the cloudwatch event. More info:

  • https://github.com/sindresorhus/query-string#user-content-nesting

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

So although you didn't indicate it in your question, I suspect you are showing the response that you are receiving as the result of this lambda post, not the raw response/event you are receiving from AWS Transcribe.

也许代替查询字符串:

var post_data = JSON.stringify(event);

这篇关于CloudWatch Events在Amazon Transcribe事件上触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆