1

キネシス分析からの CSV レコードを Sagemaker エンドポイントに送信し、ラムダ関数を介して推論を取得し、それを Firehose API に渡して S3 にダンプしようとしています。しかし、何らかの理由でデータが sagemaker に入っていません。

'use strict';
console.log('Loading function');
var AWS = require('aws-sdk');
var sagemakerruntime = new AWS.SageMakerRuntime({apiVersion: '2017-05-13'});
var firehose = new AWS.Firehose({apiVersion: '2015-08-04'});
exports.handler = (event, context, callback) => {
    let success = 0;
    let failure = 0;
    const output = event.records.map((record) => {
        /* Data is base64 encoded, so decode here */
        const recordData = Buffer.from(record.data, 'base64');
        try {
            var params = {
                Body: new Buffer('...') || recordData /* Strings will be Base-64 encoded on your behalf */, /* required */
                EndpointName: 'String', /* required */
                Accept: 'text/csv',
                ContentType: 'text/csv'
            };
            sagemakerruntime.invokeEndpoint(params, function(err, data) {
                var result1;
                if (err) console.log(err, err.stack); // an error occurred
                else     console.log(data);           // successful response
                result1=data;
                var params = {
                    DeliveryStreamName: 'String', /* required */
                    Record: { /* required */
                        Data: new Buffer('...') || result1 /* Strings will be Base-64 encoded on your behalf */ /* required */
                    }
                };
                firehose.putRecord(params, function(err, data) {
                    if (err) console.log(err, err.stack); // an error occurred
                    else     console.log(data);           // successful response
                });
            });
            success++;
            return {
                recordId: record.recordId,
                result: 'Ok',
            };
        } catch (err) {
            failure++;
            return {
                recordId: record.recordId,
                result: 'DeliveryFailed',
            };
        }
    });
    console.log(`Successful delivered records ${success}, Failed delivered records ${failure}.`);
    callback(null, {
        records: output,
    });
};

4

0 に答える 0