Skip to content

Rename host and port to lambda emulator host and port #1947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void EvaluateEnvironmentVariables(RunCommandSettings settings)
var envValue = environmentVariables[LAMBDA_RUNTIME_API_PORT]?.ToString();
if (int.TryParse(envValue, out var port))
{
settings.Port = port;
settings.LambdaEmulatorPort = port;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ public sealed class RunCommandSettings : CommandSettings
/// The hostname or IP address used for the test tool's web interface.
/// Any host other than an explicit IP address or localhost (e.g. '*', '+' or 'example.com') binds to all public IPv4 and IPv6 addresses.
/// </summary>
[CommandOption("--host <HOST>")]
[CommandOption("--lambda-emulator-host <HOST>")]
[Description(
"The hostname or IP address used for the test tool's web interface. Any host other than an explicit IP address or localhost (e.g. '*', '+' or 'example.com') binds to all public IPv4 and IPv6 addresses.")]
[DefaultValue(Constants.DefaultHost)]
public string Host { get; set; } = Constants.DefaultHost;
[DefaultValue(Constants.DefaultLambdaEmulatorHost)]
public string LambdaEmulatorHost { get; set; } = Constants.DefaultLambdaEmulatorHost;

/// <summary>
/// The port number used for the test tool's web interface.
/// </summary>
[CommandOption("-p|--port <PORT>")]
[CommandOption("-p|--lambda-emulator-port <PORT>")]
[Description("The port number used for the test tool's web interface.")]
[DefaultValue(Constants.DefaultLambdaRuntimeEmulatorPort)]
public int Port { get; set; } = Constants.DefaultLambdaRuntimeEmulatorPort;
[DefaultValue(Constants.DefaultLambdaEmulatorPort)]
public int LambdaEmulatorPort { get; set; } = Constants.DefaultLambdaEmulatorPort;

/// <summary>
/// Disable auto launching the test tool's web interface in a browser.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public abstract class Constants
/// <summary>
/// The default port used by the Lambda Test Tool for the Lambda Runtime API and the Web Interface.
/// </summary>
public const int DefaultLambdaRuntimeEmulatorPort = 5050;
public const int DefaultLambdaEmulatorPort = 5050;

/// <summary>
/// The default port used by the API Gateway Emulator.
Expand All @@ -28,7 +28,7 @@ public abstract class Constants
/// <summary>
/// The default hostname used for the Lambda Test Tool.
/// </summary>
public const string DefaultHost = "localhost";
public const string DefaultLambdaEmulatorHost = "localhost";

/// <summary>
/// The default mode for the API Gateway Emulator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static ApiGatewayEmulatorProcess Startup(RunCommandSettings settings, Can

builder.Services.AddApiGatewayEmulatorServices();

var serviceUrl = $"http://{settings.Host}:{settings.ApiGatewayEmulatorPort}";
var serviceUrl = $"http://{settings.LambdaEmulatorHost}:{settings.ApiGatewayEmulatorPort}";
builder.WebHost.UseUrls(serviceUrl);
builder.WebHost.SuppressStatusMessages(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static TestToolProcess Startup(RunCommandSettings settings, CancellationT
}
builder.Services.AddSingleton<IDirectoryManager, DirectoryManager>();

var serviceUrl = $"http://{settings.Host}:{settings.Port}";
var serviceUrl = $"http://{settings.LambdaEmulatorHost}:{settings.LambdaEmulatorPort}";
builder.WebHost.UseUrls(serviceUrl);
builder.WebHost.SuppressStatusMessages(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private void StartTestToolProcess(ApiGatewayEmulatorMode apiGatewayMode, TestCon
""Path"": ""/{config.RouteName}""
}}");
cancellationTokenSource.CancelAfter(5000);
var settings = new RunCommandSettings { Port = lambdaPort, NoLaunchWindow = true, ApiGatewayEmulatorMode = apiGatewayMode,ApiGatewayEmulatorPort = apiGatewayPort};
var settings = new RunCommandSettings { LambdaEmulatorPort = lambdaPort, NoLaunchWindow = true, ApiGatewayEmulatorMode = apiGatewayMode,ApiGatewayEmulatorPort = apiGatewayPort};
var command = new RunCommand(_mockInteractiveService.Object, _mockEnvironmentManager.Object);
var context = new CommandContext(new List<string>(), _mockRemainingArgs.Object, "run", null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public async Task ExecuteAsync_LambdaRuntimeApi_SuccessfulLaunch()
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
var cancellationSource = new CancellationTokenSource();
cancellationSource.CancelAfter(5000);
var settings = new RunCommandSettings { Port = 9001, NoLaunchWindow = true };
var settings = new RunCommandSettings { LambdaEmulatorPort = 9001, NoLaunchWindow = true };
var command = new RunCommand(_mockInteractiveService.Object, _mockEnvironmentManager.Object);
var context = new CommandContext(new List<string>(), _mockRemainingArgs.Object, "run", null);
var apiUrl = $"http://{settings.Host}:{settings.Port}";
var apiUrl = $"http://{settings.LambdaEmulatorHost}:{settings.LambdaEmulatorPort}";

// Act
var runningTask = command.ExecuteAsync(context, settings, cancellationSource);
Expand All @@ -50,10 +50,10 @@ public async Task ExecuteAsync_ApiGatewayEmulator_SuccessfulLaunch()
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
var cancellationSource = new CancellationTokenSource();
cancellationSource.CancelAfter(5000);
var settings = new RunCommandSettings { Port = 9002, ApiGatewayEmulatorMode = ApiGatewayEmulatorMode.HttpV2, NoLaunchWindow = true};
var settings = new RunCommandSettings { LambdaEmulatorPort = 9002, ApiGatewayEmulatorMode = ApiGatewayEmulatorMode.HttpV2, NoLaunchWindow = true};
var command = new RunCommand(_mockInteractiveService.Object, _mockEnvironmentManager.Object);
var context = new CommandContext(new List<string>(), _mockRemainingArgs.Object, "run", null);
var apiUrl = $"http://{settings.Host}:{settings.ApiGatewayEmulatorPort}/__lambda_test_tool_apigateway_health__";
var apiUrl = $"http://{settings.LambdaEmulatorHost}:{settings.ApiGatewayEmulatorPort}/__lambda_test_tool_apigateway_health__";

// Act
var runningTask = command.ExecuteAsync(context, settings, cancellationSource);
Expand Down Expand Up @@ -82,7 +82,7 @@ public async Task ExecuteAsync_EnvPorts_SuccessfulLaunch()
var settings = new RunCommandSettings { ApiGatewayEmulatorMode = ApiGatewayEmulatorMode.HttpV2, NoLaunchWindow = true };
var command = new RunCommand(_mockInteractiveService.Object, environmentManager);
var context = new CommandContext(new List<string>(), _mockRemainingArgs.Object, "run", null);
var apiUrl = $"http://{settings.Host}:9765/__lambda_test_tool_apigateway_health__";
var apiUrl = $"http://{settings.LambdaEmulatorHost}:9765/__lambda_test_tool_apigateway_health__";

// Act
var runningTask = command.ExecuteAsync(context, settings, cancellationSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void DefaultHost_IsSetToConstantsDefaultHost()
var settings = new RunCommandSettings();

// Assert
Assert.Equal(Constants.DefaultHost, settings.Host);
Assert.Equal(Constants.DefaultLambdaEmulatorHost, settings.LambdaEmulatorHost);
}

[Fact]
Expand All @@ -25,7 +25,7 @@ public void DefaultPort_IsSetToConstantsDefaultPort()
var settings = new RunCommandSettings();

// Assert
Assert.Equal(Constants.DefaultLambdaRuntimeEmulatorPort, settings.Port);
Assert.Equal(Constants.DefaultLambdaEmulatorPort, settings.LambdaEmulatorPort);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task RouteNotFound(ApiGatewayEmulatorMode mode, HttpStatusCode stat
var cancellationSource = new CancellationTokenSource();
cancellationSource.CancelAfter(5000);
var settings = new RunCommandSettings { ApiGatewayEmulatorPort = 9003, ApiGatewayEmulatorMode = mode, NoLaunchWindow = true};
var apiUrl = $"http://{settings.Host}:{settings.ApiGatewayEmulatorPort}/__lambda_test_tool_apigateway_health__";
var apiUrl = $"http://{settings.LambdaEmulatorHost}:{settings.ApiGatewayEmulatorPort}/__lambda_test_tool_apigateway_health__";

// Act
var process = ApiGatewayEmulatorProcess.Startup(settings, cancellationSource.Token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task AddEventToDataStore()

var cancellationTokenSource = new CancellationTokenSource();
var options = new RunCommandSettings();
options.Port = 9000;
options.LambdaEmulatorPort = 9000;
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
var testToolProcess = TestToolProcess.Startup(options, cancellationTokenSource.Token);
try
Expand Down Expand Up @@ -53,7 +53,7 @@ public async Task AddEventToDataStore()
return input.ToUpper();
};

System.Environment.SetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API", $"{options.Host}:{options.Port}/{functionName}");
System.Environment.SetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API", $"{options.LambdaEmulatorHost}:{options.LambdaEmulatorPort}/{functionName}");
_ = LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer())
.Build()
.RunAsync(cancellationTokenSource.Token);
Expand All @@ -74,7 +74,7 @@ public async Task InvokeRequestResponse()

var cancellationTokenSource = new CancellationTokenSource();
var options = new RunCommandSettings();
options.Port = 9001;
options.LambdaEmulatorPort = 9001;
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
var testToolProcess = TestToolProcess.Startup(options, cancellationTokenSource.Token);
try
Expand All @@ -85,7 +85,7 @@ public async Task InvokeRequestResponse()
return input.ToUpper();
};

System.Environment.SetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API", $"{options.Host}:{options.Port}/{functionName}");
System.Environment.SetEnvironmentVariable("AWS_LAMBDA_RUNTIME_API", $"{options.LambdaEmulatorHost}:{options.LambdaEmulatorPort}/{functionName}");
_ = LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer())
.Build()
.RunAsync(cancellationTokenSource.Token);
Expand Down
Loading