【问题标题】:AWS KinesisEvents package not found when building Lambda function构建 Lambda 函数时未找到 AWS KinesisEvents 包
【发布时间】:2021-10-29 17:00:57
【问题描述】:

我一直在尝试为 .NET Core 项目(连接到 Kinesis 流)构建 AWS Lambda 函数,以便我可以将该函数部署到云环境,但我一直收到以下错误功能:error CS0234: The type or namespace name 'KinesisEvents' does not exist in the namespace 'Amazon.Lambda' (are you missing an assembly reference?)。我已确保按照here 的建议安装最新版本的AWS SDK for .NET package AWSSDK.Kinesis,并且我有 已安装 Amazon.Lambda.Templates 版本 3.8.1。我还安装了最新版本的 Amazon.Lambda.Tools (5.1.4) 以及 .NET Core 2.1.9。

什么会导致无法识别 KinesisEvents 包名称?

下面是 lambda 的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Amazon.Kinesis;
using Amazon.Kinesis.Model;
using Amazon.Lambda.Core;
using Amazon.Lambda.KinesisEvents;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]

namespace BookOnlineButton.PracticeBudgetAvailabilityLambda
{
    public class Function
    {

        /// <summary>
        ///
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public string FunctionHandler(KinesisEvent kinesisEvent, ILambdaContext context)
        {
            context.Logger.LogLine($"Beginning to process {kinesisEvent.Records.Count} records...");

            foreach (var record in kinesisEvent.Records)
            {
                string recordData = GetRecordContents(record.Kinesis);
                context.Logger.LogLine($"Record Data:");
                context.Logger.LogLine(recordData);

            }

            context.Logger.LogLine("Stream processing complete.");
        }

        private string GetRecordContents(KinesisEvent.Record streamRecord)
        {
            var reader = new StreamReader(streamRecord.Data, Encoding.UTF8);
            try{
                return reader.ReadToEnd();
            }
            finally{
                reader?.Dispose();
            }
        }
    }
}

【问题讨论】:

  • 您尝试从引用中删除 Amazon.Lambda.Core,尝试导入。
  • 您能否也分享 .csproj 文件以便更好地理解问题

标签: c# amazon-web-services asp.net-core aws-lambda amazon-kinesis


【解决方案1】:

即使 KinesisEvents 包应该是 Amazon.Lamda 包的一部分,我最终还是不得不单独安装 Amazon.Lambda.KinesisEvents nuget 包才能识别 KinesisEvents 类型。

【讨论】:

    猜你喜欢
    • 2018-11-09
    • 2022-06-22
    • 2017-09-16
    • 1970-01-01
    • 2021-11-20
    • 1970-01-01
    • 2018-07-07
    • 2019-09-28
    • 2020-06-16
    相关资源
    最近更新 更多