【问题标题】:AWS Firehose transform Lambda function throws Lambda.MissingRecordId error for every recordAWS Firehose 转换 Lambda 函数为每条记录引发 Lambda.MissingRecordId 错误
【发布时间】:2020-09-15 13:56:41
【问题描述】:

我正在使用带有 S3 备份和 S3 目标存储桶的 AWS firehose,效果很好。当我尝试使用 Lambda 函数转换数据时出现问题。

我正在使用 .NET AWS 开发工具包,我的 Lambda 函数是用 C# 编写的,并且正在使用包含的 firehose 转换示例:

[assembly:LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.JsonSerializer))]

namespace LambdaFunctions
{
    public class Function
    {
        public KinesisFirehoseResponse FunctionHandler(KinesisFirehoseEvent evnt, ILambdaContext context)
        {
            context.Logger.LogLine($"InvocationId: {evnt.InvocationId}");
            context.Logger.LogLine($"DeliveryStreamArn: {evnt.DeliveryStreamArn}");
            context.Logger.LogLine($"Region: {evnt.Region}");

            KinesisFirehoseResponse response = new KinesisFirehoseResponse
            {
                Records = new List<KinesisFirehoseResponse.FirehoseRecord>()
            };

            foreach (KinesisFirehoseEvent.FirehoseRecord record in evnt.Records)
            {
                context.Logger.LogLine($"\tRecordId: {record.RecordId}");
                context.Logger.LogLine($"\t\tApproximateArrivalEpoch: {record.ApproximateArrivalEpoch}");
                context.Logger.LogLine($"\t\tApproximateArrivalTimestamp: {record.ApproximateArrivalTimestamp}");
                context.Logger.LogLine($"\t\tData: {record.DecodeData()}");

                // Transform data: For example ToUpper the data
                KinesisFirehoseResponse.FirehoseRecord transformedRecord = new KinesisFirehoseResponse.FirehoseRecord
                {
                    RecordId = record.RecordId,
                    Result = KinesisFirehoseResponse.TRANSFORMED_STATE_OK
                };

                transformedRecord.EncodeData(record.DecodeData().ToUpperInvariant());

                response.Records.Add(transformedRecord);
            }

            return response;
        }
    }
}

转换 Lambda 函数成功且正确地处理了数据(如测试和日志所示)。

但是,Lambda 函数没有成功将数据返回到 S3 目标存储桶,所有记录均未成功处理。

每条记录都会返回此错误:

{
    "attemptsMade": 1,
    "arrivalTimestamp": 1590656820209,
    "errorCode": "Lambda.MissingRecordId",
    "errorMessage": "One or more record Ids were not returned. Ensure that the Lambda function returns all received record Ids.",
    "attemptEndingTimestamp": 1590656883464,
    "rawData": "dGVzdDE=",
    "lambdaArn": "arn:aws:lambda:Region:AccountNumber:function:transform-function:$LATEST"
}

我不知道为什么或在何处发生此错误。我知道 Lambda 函数正在返回正确的响应,包括 recordId。

我已经重新创建了所有资源,应用了又重新应用了权限,几乎完成了我能想到的所有事情。

使用 Node.js 或 Python 版本时不会出现此问题,它似乎是 .NET 实现所独有的。

编辑:

我忘记将序列化程序程序集属性添加到最终成为问题根源的原始代码块中。

【问题讨论】:

    标签: c# amazon-web-services amazon-s3 aws-lambda amazon-kinesis-firehose


    【解决方案1】:

    AWS提供的C#例子已经过时了,特别是这个序列化包:

    Amazon.Lambda.Serialization.SystemTextJson
    

    要解决这个问题,只需用这个替换包:

    Amazon.Lambda.Serialization.Json
    

    并像这样更新程序集属性:

    [assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
    
    namespace LambdaFunctions
    {
        ...
    

    AWS 文档here 中的“序列化 Lambda 函数”下提到了此序列化包。

    但是,Amazon 尚未更新 SDK 示例以反映此更改(或至少具体来说是此示例),导致功能在部署时失败。

    【讨论】:

      猜你喜欢
      • 2021-10-31
      • 2020-07-11
      • 2020-11-06
      • 2018-07-02
      • 1970-01-01
      • 2018-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多