首页 > 解决方案 > 由于 RpcException DeadlineExceeded,无法从 Lambda 将事件附加到 EventStoreDb

问题描述

我在 C# 中有一个带有 netcoreapp3.1 的简​​单 AWS lambda,它尝试使用 gRPC 客户端 ( EventStore.Client.Grpc.Streams) 将一些事件附加到 EventStoreDb 中的流中。

在本地,(在 AWS Lambda 之外)我可以针对我的远程 EventStoreDb 正确使用相同的功能。当部署为 AWS Lambda 时,我得到了异常

{
  "errorType": "RpcException",
  "errorMessage": "Status(StatusCode=DeadlineExceeded, Detail=\"\")",
  "stackTrace": [
    "at EventStore.Client.Interceptors.TypedExceptionInterceptor.<AsyncClientStreamingCall>b__5_0[TRequest,TResponse](Task`1 t)",
    "at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()",
    "at System.Threading.Tasks.Task.<>c.<.cctor>b__274_0(Object obj)",
    "at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)",
    "--- End of stack trace from previous location where exception was thrown ---",
    "at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)",
    "at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)",
    "--- End of stack trace from previous location where exception was thrown ---",
    "at EventStore.Client.EventStoreClient.AppendToStreamInternal(AppendReq header, IEnumerable`1 eventData, EventStoreClientOperationOptions operationOptions, UserCredentials userCredentials, CancellationToken cancellationToken)",
    "at EventStoreDb.LambdaSample.EventStore.Append(String streamName, Int32 aggregateVersion, IEnumerable`1 events, CancellationToken cancellationToken) in /mnt/c/src/issue-lambda-eventstore/src/EventStoreDb.LambdaSample/EventStore.cs:line 25",
    "at EventStoreDb.LambdaSample.LambdaEntryPoint.FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context) in /mnt/c/src/issue-lambda-eventstore/src/EventStoreDb.LambdaSample/LambdaEntryPoint.cs:line 52",
    "at lambda_method(Closure , Stream , Stream , LambdaContextInternal )"
  ]
}

该问题可以重现,我在此处添加了代码:https ://gitlab.com/sunnyatticsoftware/sandbox/issue-lambda-eventstore 以及有关如何使用 AWS CLI 部署/运行 lambda 函数的说明。

请注意,说明所指的角色的 ARN 可能与您的情况不同,并且它使用 my--profile diegosasw您必须在您自己的 AWS CLI 中进行修改

代码在 repo 中,但作为总结,这是失败的简单函数

public async Task<APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
{
    context.Logger.LogLine("Get Request\n");
    context.Logger.LogLine("Storing sample events in event store");

    var eventStoreClient = EventStoreClientFactory.Create(ConnectionString);
    var serializationService = new SerializationService(SupportedTypes.Default);
    var eventStore = new global::EventStoreDb.LambdaSample.EventStore(eventStoreClient, serializationService);
    var foo = new Foo("First event");
    var bar = new Bar( "Second event");

    var events = new List<object> {foo, bar};

    var id = Guid.NewGuid();
    var streamName = $"SampleLambda-{id}";
    
    // this is my own wrapper function
    await eventStore.Append(streamName, events.Count, events, CancellationToken.None);
    
    var response = new APIGatewayProxyResponse
    {
        StatusCode = (int)HttpStatusCode.OK,
        Body = "Events persisted successfully",
        Headers = new Dictionary<string, string> { { "Content-Type", "text/plain" } }
    };

    return response;
}

更新:我也在这里创建了它:https ://discuss.eventstore.com/t/grpc-core-rpcexception-deadlineexceeded-in-aws-lambda/3174

标签: c#aws-lambdaeventstoredb

解决方案


推荐阅读