aws / aws/aws-lambda-dotnet

Exceeded maximum allowed payload size

オープン
#1,815 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug low-effort module/lambda-client-lib p2 queued
主要言語
C#
スター
1.7k
フォーク
503
平均マージ
1日 13時間
マージ済み PR(30日)
19

説明

### Describe the bug

Hi,

We have an ASP.NET Core Web API running, hosted in a Lambda function. The API uses Top Level Statements and the package [Amazon.Lambda.AspNetCoreServer.Hosting](https://github.com/aws/aws-lambda-dotnet/tree/master/Libraries/src/Amazon.Lambda.AspNetCoreServer.Hosting).

The function acts as a Proxy Server which enables our API clients to access a lot of legacy SOAP services. In front of the Lambda function there is an API Gateway.

Some of the responses from the SOAP Services exceeds the Lambda response limit of 6MB. When this occurs the underlying Lambda runtime client receives an HTTP 413 error and [throws an exception](https://github.com/aws/aws-lambda-dotnet/blob/e24c52fa59db72bc83824020d267321a81410c07/Libraries/src/Amazon.Lambda.RuntimeSupport/Client/InternalClientAdapted.cs#L406) which crashes the whole application, because this happens during startup of the .net application.

I'm not sure if it is a bug or not. How can we handle those errors. In such cases the calling client application should also receive HTTP 413 and not 500.

### Regression Issue

- [ ] Select this option if this issue appears to be a regression.

### Expected Behavior

Application doesn't crash, exception can be handled and send back to the client.

### Current Behavior

When response size is greater than 6 MB, Lambda function receives an HTTP 413 error and crashes. The calling client receives a HTTP 500 error, probably because of the crashed application. The exception occurs during startup of the application:

`{"errorMessage":"Exceeded maximum allowed payload size (6291556 bytes).","errorType":"RequestEntityTooLarge"}`

```
at Amazon.Lambda.RuntimeSupport.InternalRuntimeApiClient.ResponseAsync(String awsRequestId, Stream outputStream, CancellationToken cancellationToken)
at Amazon.Lambda.RuntimeSupport.RuntimeApiClient.SendResponseAsync(String awsRequestId, Stream outputStream, CancellationToken cancellationToken)
at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.InvokeOnceAsync(CancellationToken cancellationToken)
at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.RunAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.Internal.Host.b__15_1(IHostedService service, CancellationToken token)
at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation)
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
at Program.$(String[] args) in Program.cs:line 56
```

### Reproduction Steps

n/a

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### AWS .NET SDK and/or Package version used

Amazon.Lambda.AspNetCoreServer.Hosting 1.7.0

### Targeted .NET Platform

.NET Core 8.0

### Operating System and version

Docker container

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

InternalClientAdapted.cs の 406 行目付近から始め、LambdaBootstrap.InvokeOnceAsync と stack trace に示されている ASP.NET Core hosting の起動を通じて例外を追跡します。.NET 8 上の Amazon.Lambda.AspNetCoreServer.Hosting 1.7.0 で、6 MB のレスポンスパスを再現または調査します。サイズ超過のレスポンスによって起動がクラッシュせず、呼び出し元のクライアントが 500 ではなく HTTP 413 を受け取れば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
aws, csharp, docker
領域
api, backend, cloud
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
説明が足りない
初心者へのやさしさ
42/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。