Skip to content

Commit cf39cc7

Browse files
committed
PR comments
1 parent 9e4e6a0 commit cf39cc7

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Components/Pages/Home.razor.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,14 @@ private async Task<bool> InvokeLambdaFunction(string payload)
352352
}
353353
catch (AmazonLambdaException e)
354354
{
355+
Logger.LogInformation(e.Message);
356+
355357
// lambda client automatically adds some extra verbiage: "The service returned an error with Error Code xxxx and HTTP Body: <bodyhere>".
356358
// removing the extra verbiage to make the error message smaller and look better on the ui.
357359
_errorMessage = e.Message.Contains("HTTP Body: ")
358360
? e.Message.Split("HTTP Body: ")[1]
359-
: e.Message; }
361+
: e.Message;
362+
}
360363
return false;
361364
}
362365
}

Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Extensions/InvokeResponseExtensions.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,19 @@ public static APIGatewayProxyResponse ToApiGatewayErrorResponse(ApiGatewayEmulat
8787

8888
/// <summary>
8989
/// Creates a standard API Gateway response for a "Request Entity Too Large" (413) error.
90+
/// Not compatible with HTTP V2 API Gateway mode.
9091
/// </summary>
91-
/// <param name="emulatorMode">The API Gateway emulator mode (Rest or Http).</param>
92+
/// <param name="emulatorMode">The API Gateway emulator mode (Rest or HttpV1 only).</param>
9293
/// <returns>An APIGatewayProxyResponse configured with:
9394
/// - Status code 413
94-
/// - JSON error message
95+
/// - JSON error message ("Request Too Long" for REST, "Request Entity Too Large" for HTTP V1)
9596
/// - Content-Type header set to application/json
9697
/// </returns>
98+
/// <exception cref="InvalidOperationException">Thrown when emulatorMode is HttpV2 or invalid value</exception>
99+
/// <remarks>
100+
/// This method only supports REST and HTTP V1 API Gateway modes. For HTTP V2,
101+
/// use <seealso cref="ToHttpApiV2RequestTooLargeResponse"/>.
102+
/// </remarks>
97103
public static APIGatewayProxyResponse ToHttpApiRequestTooLargeResponse(ApiGatewayEmulatorMode emulatorMode)
98104
{
99105
if (emulatorMode == ApiGatewayEmulatorMode.Rest)
@@ -122,7 +128,7 @@ public static APIGatewayProxyResponse ToHttpApiRequestTooLargeResponse(ApiGatewa
122128
IsBase64Encoded = false
123129
};
124130
}
125-
throw new InvalidOperationException();
131+
throw new ArgumentException($"Unsupported API Gateway emulator mode: {emulatorMode}. Only Rest and HttpV1 modes are supported.");
126132
}
127133

128134
/// <summary>

Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Models/LambdaOptions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33

44
namespace Amazon.Lambda.TestTool.Models;
55

6+
/// <summary>
7+
/// Configuration options for invoking lambda functions.
8+
/// </summary>
69
public class LambdaOptions
710
{
11+
/// <summary>
12+
/// Gets or sets the endpoint URL for Lambda function invocations.
13+
/// </summary>
14+
/// <value>
15+
/// A string containing the endpoint URL. Defaults to an empty string.
16+
/// </value>
817
public string Endpoint { get; set; } = string.Empty;
918
}

Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.IntegrationTests/ApiGatewayEmulatorProcessTests.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,17 +301,15 @@ public async Task TestLambdaWithLargeRequestPayload_RestAndV1(ApiGatewayEmulator
301301

302302
var handler = (APIGatewayProxyRequest request, ILambdaContext context) =>
303303
{
304-
var env = Environment.GetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API");
305-
testOutputHelper.WriteLine($"TestLambdaWithLargeRequestPayload {mode}: {env}");
306304
return new APIGatewayProxyResponse
307305
{
308306
StatusCode = 200,
309307
Body = request.Body.Length.ToString()
310308
};
311309
};
312310

313-
Environment.SetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API", $"localhost:{lambdaPort}/largerequestfunction");
314311
_ = LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer())
312+
.ConfigureOptions(x => x.RuntimeApiEndpoint = $"localhost:{lambdaPort}/largerequestfunction")
315313
.Build()
316314
.RunAsync(_cancellationTokenSource.Token);
317315

@@ -346,17 +344,15 @@ public async Task TestLambdaWithLargeRequestPayload_HttpV2()
346344

347345
var handler = (APIGatewayHttpApiV2ProxyRequest request, ILambdaContext context) =>
348346
{
349-
var env = Environment.GetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API");
350-
testOutputHelper.WriteLine($"TestLambdaWithLargeRequestPayload HttpV2: {env}");
351347
return new APIGatewayHttpApiV2ProxyResponse
352348
{
353349
StatusCode = 200,
354350
Body = request.Body.Length.ToString()
355351
};
356352
};
357353

358-
Environment.SetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API", $"localhost:{lambdaPort}/largerequestfunction");
359354
_ = LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer())
355+
.ConfigureOptions(x => x.RuntimeApiEndpoint = $"localhost:{lambdaPort}/largerequestfunction")
360356
.Build()
361357
.RunAsync(_cancellationTokenSource.Token);
362358

0 commit comments

Comments
 (0)