diff --git a/.autover/changes/27264eba-d94e-4190-a5ab-91c895db6b45.json b/.autover/changes/27264eba-d94e-4190-a5ab-91c895db6b45.json new file mode 100644 index 000000000..4d400c45e --- /dev/null +++ b/.autover/changes/27264eba-d94e-4190-a5ab-91c895db6b45.json @@ -0,0 +1,11 @@ +{ + "Projects": [ + { + "Name": "Amazon.Lambda.TestTool", + "Type": "Patch", + "ChangelogMessages": [ + "Add support for configuring HTTPS endpoints for the Lambda UI emulator and API Gateway emulator" + ] + } + ] +} \ No newline at end of file diff --git a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/RunCommand.cs b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/RunCommand.cs index f366c2f83..036611cd5 100644 --- a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/RunCommand.cs +++ b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/RunCommand.cs @@ -21,7 +21,9 @@ public sealed class RunCommand( IToolInteractiveService toolInteractiveService, IEnvironmentManager environmentManager) : CancellableAsyncCommand { public const string LAMBDA_RUNTIME_API_PORT = "LAMBDA_RUNTIME_API_PORT"; + public const string LAMBDA_WEB_UI_HTTPS_PORT = "LAMBDA_WEB_UI_HTTPS_PORT"; public const string API_GATEWAY_EMULATOR_PORT = "API_GATEWAY_EMULATOR_PORT"; + public const string API_GATEWAY_EMULATOR_HTTPS_PORT = "API_GATEWAY_EMULATOR_HTTPS_PORT"; /// /// Task for the Lambda Runtime API. @@ -37,10 +39,10 @@ public override async Task ExecuteAsync(CommandContext context, RunCommandS { EvaluateEnvironmentVariables(settings); - if (!settings.LambdaEmulatorPort.HasValue && !settings.ApiGatewayEmulatorPort.HasValue && string.IsNullOrEmpty(settings.SQSEventSourceConfig)) + if (!settings.LambdaEmulatorPort.HasValue && !settings.ApiGatewayEmulatorPort.HasValue && !settings.ApiGatewayEmulatorHttpsPort.HasValue && string.IsNullOrEmpty(settings.SQSEventSourceConfig)) { throw new ArgumentException("At least one of the following parameters must be set: " + - "--lambda-emulator-port, --api-gateway-emulator-port or --sqs-eventsource-config"); + "--lambda-emulator-port, --api-gateway-emulator-port, --api-gateway-emulator-https-port or --sqs-eventsource-config"); } var tasks = new List(); @@ -69,11 +71,11 @@ public override async Task ExecuteAsync(CommandContext context, RunCommandS } } - if (settings.ApiGatewayEmulatorPort.HasValue) + if (settings.ApiGatewayEmulatorPort.HasValue || settings.ApiGatewayEmulatorHttpsPort.HasValue) { if (settings.ApiGatewayEmulatorMode is null) { - throw new ArgumentException("When --api-gateway-emulator-port is set the --api-gateway-emulator-mode must be set to configure the mode for the API Gateway emulator."); + throw new ArgumentException("When --api-gateway-emulator-port or --api-gateway-emulator-https-port is set the --api-gateway-emulator-mode must be set to configure the mode for the API Gateway emulator."); } var apiGatewayEmulatorProcess = @@ -137,6 +139,18 @@ private void EvaluateEnvironmentVariables(RunCommandSettings settings) throw new ArgumentException($"Value for {LAMBDA_RUNTIME_API_PORT} environment variable was not a valid port number"); } } + if (environmentVariables.Contains(LAMBDA_WEB_UI_HTTPS_PORT)) + { + var envValue = environmentVariables[LAMBDA_WEB_UI_HTTPS_PORT]?.ToString(); + if (int.TryParse(envValue, out var port)) + { + settings.LambdaEmulatorHttpsPort = port; + } + else + { + throw new ArgumentException($"Value for {LAMBDA_WEB_UI_HTTPS_PORT} environment variable was not a valid port number"); + } + } if (environmentVariables.Contains(API_GATEWAY_EMULATOR_PORT)) { var envValue = environmentVariables[API_GATEWAY_EMULATOR_PORT]?.ToString(); @@ -149,6 +163,18 @@ private void EvaluateEnvironmentVariables(RunCommandSettings settings) throw new ArgumentException($"Value for {API_GATEWAY_EMULATOR_PORT} environment variable was not a valid port number"); } } + if (environmentVariables.Contains(API_GATEWAY_EMULATOR_HTTPS_PORT)) + { + var envValue = environmentVariables[API_GATEWAY_EMULATOR_HTTPS_PORT]?.ToString(); + if (int.TryParse(envValue, out var port)) + { + settings.ApiGatewayEmulatorHttpsPort = port; + } + else + { + throw new ArgumentException($"Value for {API_GATEWAY_EMULATOR_HTTPS_PORT} environment variable was not a valid port number"); + } + } if (settings.SQSEventSourceConfig != null && settings.SQSEventSourceConfig.StartsWith(Constants.ArgumentEnvironmentVariablePrefix, StringComparison.CurrentCultureIgnoreCase)) { diff --git a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/Settings/RunCommandSettings.cs b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/Settings/RunCommandSettings.cs index 607c2ce40..0584eaa30 100644 --- a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/Settings/RunCommandSettings.cs +++ b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/Settings/RunCommandSettings.cs @@ -30,6 +30,15 @@ public sealed class RunCommandSettings : CommandSettings [Description("The port number used for the test tool's web interface.")] public int? LambdaEmulatorPort { get; set; } + /// + /// The https port number used for the test tool's web interface. This is only used for the web UI. Lambda functions making REST calls to the Lambda Runtime API + /// always use http configured by the port specified in . To use HTTPS the environment must be configured with certs + /// for the host specified in . + /// + [CommandOption("--lambda-emulator-https-port ")] + [Description("The https port number used for the test tool's web interface.")] + public int? LambdaEmulatorHttpsPort { get; set; } + /// /// Disable auto launching the test tool's web interface in a browser. /// @@ -49,12 +58,22 @@ public sealed class RunCommandSettings : CommandSettings public ApiGatewayEmulatorMode? ApiGatewayEmulatorMode { get; set; } /// - /// The port number used for the test tool's API Gateway emulator. If a port is specified the API Gateway emulator will be started. The --api-gateway-mode muse also be set when setting the API Gateway emulator port. + /// The port number used for the test tool's API Gateway emulator. If a port is specified the API Gateway emulator will be started. The --api-gateway-emulator-mode + /// must also be set when setting the API Gateway emulator port. /// [CommandOption("--api-gateway-emulator-port ")] [Description("The port number used for the test tool's API Gateway emulator.")] public int? ApiGatewayEmulatorPort { get; set; } + /// + /// The https port number used for the test tool's API Gateway emulator. If a port is specified the API Gateway emulator will be started. The --api-gateway--emulator-mode must + /// also be set when setting the API Gateway emulator port. To use HTTPS the environment must be configured with certs + /// for the host specified in . + /// + [CommandOption("--api-gateway-emulator-https-port ")] + [Description("The https port number used for the test tool's API Gateway emulator.")] + public int? ApiGatewayEmulatorHttpsPort { get; set; } + /// /// The configuration for the SQS event source. The format of the config is a comma delimited key pairs. For example \"QueueUrl=queue-url,FunctionName=function-name,VisibilityTimeout=100\". /// Possible keys are: BatchSize, DisableMessageDelete, FunctionName, LambdaRuntimeApi, Profile, QueueUrl, Region, VisibilityTimeout diff --git a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Processes/ApiGatewayEmulatorProcess.cs b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Processes/ApiGatewayEmulatorProcess.cs index 0ddb448a1..b09c74e12 100644 --- a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Processes/ApiGatewayEmulatorProcess.cs +++ b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Processes/ApiGatewayEmulatorProcess.cs @@ -54,8 +54,22 @@ public static ApiGatewayEmulatorProcess Startup(RunCommandSettings settings, Can builder.Services.AddApiGatewayEmulatorServices(); builder.Services.AddSingleton(); - var serviceUrl = $"http://{settings.LambdaEmulatorHost}:{settings.ApiGatewayEmulatorPort}"; - builder.WebHost.UseUrls(serviceUrl); + string? serviceHttpUrl = null; + string? serviceHttpsUrl = null; + var serviceUrls = new List(); + + if (settings.ApiGatewayEmulatorPort.HasValue) + { + serviceHttpUrl = $"http://{settings.LambdaEmulatorHost}:{settings.ApiGatewayEmulatorPort}"; + serviceUrls.Add(serviceHttpUrl); + } + if (settings.ApiGatewayEmulatorHttpsPort.HasValue) + { + serviceHttpsUrl = $"https://{settings.LambdaEmulatorHost}:{settings.ApiGatewayEmulatorHttpsPort}"; + serviceUrls.Add(serviceHttpsUrl); + } + + builder.WebHost.UseUrls(serviceUrls.ToArray()); builder.WebHost.SuppressStatusMessages(true); builder.Services.AddHealthChecks(); @@ -66,7 +80,7 @@ public static ApiGatewayEmulatorProcess Startup(RunCommandSettings settings, Can app.Lifetime.ApplicationStarted.Register(() => { - app.Logger.LogInformation("The API Gateway Emulator is available at: {ServiceUrl}", serviceUrl); + app.Logger.LogInformation("The API Gateway Emulator is available at: {ServiceUrl}", serviceHttpsUrl ?? serviceHttpUrl); }); app.Map("/{**catchAll}", async (HttpContext context, IApiGatewayRouteConfigService routeConfigService, ILambdaClient lambdaClient) => @@ -160,7 +174,7 @@ public static ApiGatewayEmulatorProcess Startup(RunCommandSettings settings, Can { Services = app.Services, RunningTask = runTask, - ServiceUrl = serviceUrl + ServiceUrl = serviceHttpsUrl ?? serviceHttpUrl ?? throw new InvalidOperationException("No valid service URL was configured for the API Gateway emulator.") }; } } diff --git a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Processes/TestToolProcess.cs b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Processes/TestToolProcess.cs index ce66305a1..61a0a8aa5 100644 --- a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Processes/TestToolProcess.cs +++ b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Processes/TestToolProcess.cs @@ -66,8 +66,20 @@ public static TestToolProcess Startup(RunCommandSettings settings, CancellationT } builder.Services.AddSingleton(); - var serviceUrl = $"http://{settings.LambdaEmulatorHost}:{settings.LambdaEmulatorPort}"; - builder.WebHost.UseUrls(serviceUrl); + var serviceHttp = $"http://{settings.LambdaEmulatorHost}:{settings.LambdaEmulatorPort}"; + + string? serviceHttps = null; + + if (settings.LambdaEmulatorHttpsPort.HasValue) + { + serviceHttps = $"https://{settings.LambdaEmulatorHost}:{settings.LambdaEmulatorHttpsPort}"; + builder.WebHost.UseUrls(serviceHttp, serviceHttps); + } + else + { + builder.WebHost.UseUrls(serviceHttp); + } + builder.WebHost.SuppressStatusMessages(true); builder.Services.AddSingleton(); @@ -102,7 +114,7 @@ public static TestToolProcess Startup(RunCommandSettings settings, CancellationT { Services = app.Services, RunningTask = runTask, - ServiceUrl = serviceUrl + ServiceUrl = serviceHttps ?? serviceHttp }; return startup;