Skip to content

Commit 9ea2aca

Browse files
committed
Use default host and port if endpoint not specified
1 parent 694d028 commit 9ea2aca

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Processes/ApiGatewayEmulatorProcess.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public static ApiGatewayEmulatorProcess Startup(RunCommandSettings settings, Can
9696
PayloadStream = lambdaRequestStream
9797
};
9898

99-
using var lambdaClient = CreateLambdaServiceClient(routeConfig);
99+
using var lambdaClient = CreateLambdaServiceClient(routeConfig, settings);
100100
var response = await lambdaClient.InvokeAsync(invokeRequest);
101101

102102
if (response.FunctionError != null)
@@ -111,13 +111,11 @@ public static ApiGatewayEmulatorProcess Startup(RunCommandSettings settings, Can
111111
{
112112
var lambdaResponse = response.ToApiGatewayHttpApiV2ProxyResponse();
113113
await lambdaResponse.ToHttpResponseAsync(context);
114-
return;
115114
}
116115
else
117116
{
118117
var lambdaResponse = response.ToApiGatewayProxyResponse(settings.ApiGatewayEmulatorMode.Value);
119118
await lambdaResponse.ToHttpResponseAsync(context, settings.ApiGatewayEmulatorMode.Value);
120-
return;
121119
}
122120
});
123121

@@ -131,12 +129,27 @@ public static ApiGatewayEmulatorProcess Startup(RunCommandSettings settings, Can
131129
};
132130
}
133131

134-
private static IAmazonLambda CreateLambdaServiceClient(ApiGatewayRouteConfig routeConfig)
132+
/// <summary>
133+
/// Creates an Amazon Lambda service client with the specified configuration.
134+
/// </summary>
135+
/// <param name="routeConfig">The API Gateway route configuration containing the endpoint information.
136+
/// If the endpoint is specified in routeConfig, it will be used as the service URL.</param>
137+
/// <param name="settings">The run command settings containing host and port information.
138+
/// If routeConfig endpoint is null, the service URL will be constructed using settings.Host and settings.Port.</param>
139+
/// <returns>An instance of IAmazonLambda configured with the specified endpoint and credentials.</returns>
140+
/// <remarks>
141+
/// The function uses hard-coded AWS credentials ("accessKey", "secretKey") for authentication since they are not actually being used.
142+
/// The service URL is determined by either:
143+
/// - Using routeConfig.Endpoint if it's not null
144+
/// - Combining settings.Host and settings.Port if routeConfig.Endpoint is null
145+
/// </remarks>
146+
private static IAmazonLambda CreateLambdaServiceClient(ApiGatewayRouteConfig routeConfig, RunCommandSettings settings)
135147
{
136-
// TODO: Handle routeConfig.Endpoint to null and use the settings versions of runtime.
148+
var endpoint = routeConfig.Endpoint ?? $"http://{settings.Host}:{settings.Port}";
149+
137150
var lambdaConfig = new AmazonLambdaConfig
138151
{
139-
ServiceURL = routeConfig.Endpoint
152+
ServiceURL = endpoint
140153
};
141154

142155
return new AmazonLambdaClient(new Amazon.Runtime.BasicAWSCredentials("accessKey", "secretKey"), lambdaConfig);

0 commit comments

Comments
 (0)