Skip to content

Add port environment variables for Aspire integration #1942

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
merged 4 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<Description>A tool to help debug and test your .NET AWS Lambda functions locally.</Description>
Expand All @@ -16,7 +16,7 @@
<Version>0.0.1-beta.1</Version>
</PropertyGroup>

<ItemGroup>
<ItemGroup Condition="$(Configuration) == 'Release'">
<None Include="$(OutputPath)\publish\wwwroot\" Pack="true" PackagePath="tools\net8.0\any\wwwroot" Visible="false" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,11 @@ public static async Task<APIGatewayProxyRequest> ToApiGatewayRequest(

if (emulatorMode == ApiGatewayEmulatorMode.Rest) // rest uses encoded value for the path params
{
#pragma warning disable SYSLIB0013 // Type or member is obsolete
var encodedPathParameters = pathParameters.ToDictionary(
kvp => kvp.Key,
kvp => Uri.EscapeUriString(kvp.Value)); // intentionally using EscapeURiString over EscapeDataString since EscapeURiString correctly handles reserved characters :/?#[]@!$&'()*+,;= in this case
kvp => Uri.EscapeUriString(kvp.Value)); // intentionally using EscapeUriString over EscapeDataString since EscapeUriString correctly handles reserved characters :/?#[]@!$&'()*+,;= in this case
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no better way for us to have the same behavior without using an obsolete method? What if they drop it in .NET10?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gcbeattyAWS Can you answer this question since this was your change?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so i tried looking for an alternative function that was not deprecated and produced the same output that we needed - but i could not find any. i think i tried 5 or 6 different ways and spent a couple hours on it. If we want to ensure the function never gets dropped I think we could just re-implement/copy their source code for it no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not worried about the method being dropped. Methods being dropped from the BCL is a big deal that is rarely done.

#pragma warning restore SYSLIB0013 // Type or member is obsolete
pathParameters = encodedPathParameters;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static APIGatewayProxyResponse ToApiGatewayProxyResponse(this InvokeRespo
string responseJson = reader.ReadToEnd();
try
{
return JsonSerializer.Deserialize<APIGatewayProxyResponse>(responseJson);
return JsonSerializer.Deserialize<APIGatewayProxyResponse>(responseJson)!;
}
catch
{
Expand Down Expand Up @@ -132,7 +132,7 @@ private static APIGatewayHttpApiV2ProxyResponse ToHttpApiV2Response(string respo
// It has a statusCode property, so try to deserialize as full response
try
{
return JsonSerializer.Deserialize<APIGatewayHttpApiV2ProxyResponse>(response);
return JsonSerializer.Deserialize<APIGatewayHttpApiV2ProxyResponse>(response)!;
}
catch
{
Expand All @@ -155,7 +155,7 @@ private static APIGatewayHttpApiV2ProxyResponse ToHttpApiV2Response(string respo
// return "test", it actually comes as "\"test\"" to response. So we need to get the raw string which is what api gateway does.
if (jsonElement.ValueKind == JsonValueKind.String)
{
response = jsonElement.GetString();
response = jsonElement.GetString()!;
}

}
Expand Down
15 changes: 14 additions & 1 deletion Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,17 @@
config.SetApplicationName(Constants.ToolName);
});

return await app.RunAsync(args);
var arguments = new List<string>(args);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("LAMBDA_RUNTIME_API_PORT")))
{
arguments.Add("--port");
arguments.Add(Environment.GetEnvironmentVariable("LAMBDA_RUNTIME_API_PORT")!);
}
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("API_GATEWAY_EMULATOR_PORT")))
{
arguments.Add("--api-gateway-emulator-port");
arguments.Add(Environment.GetEnvironmentVariable("API_GATEWAY_EMULATOR_PORT")!);
}

return await app.RunAsync(arguments);
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static (IDictionary<string, string>, IDictionary<string, IList<string>>)
{
var key = lowerCaseKeyName ? header.Key.ToLower() : header.Key;
singleValueHeaders[key] = header.Value.Last() ?? "";
multiValueHeaders[key] = [.. header.Value];
multiValueHeaders[key] = [.. header.Value!];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the null warnings happening in this file were a false positive. They warnings only show up when doing dotnet pack not in VS. And the Value is a struct so it can't be null.

}

return (singleValueHeaders, multiValueHeaders);
Expand All @@ -133,7 +133,7 @@ public static (IDictionary<string, string>, IDictionary<string, IList<string>>)
foreach (var param in query)
{
singleValueParams[param.Key] = param.Value.Last() ?? "";
multiValueParams[param.Key] = [.. param.Value];
multiValueParams[param.Key] = [.. param.Value!];
}

return (singleValueParams, multiValueParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static Dictionary<string, string> ExtractPathParameters(string routeTempl

foreach (var param in template.Parameters)
{
if (routeValues.TryGetValue(param.Name, out var value))
if (routeValues.TryGetValue(param.Name!, out var value))
{
var stringValue = value?.ToString() ?? string.Empty;

Expand All @@ -51,7 +51,7 @@ public static Dictionary<string, string> ExtractPathParameters(string routeTempl
}

// Restore original parameter name
var originalParamName = RestoreOriginalParamName(param.Name);
var originalParamName = RestoreOriginalParamName(param.Name!);
result[originalParamName] = stringValue;
}
}
Expand Down
Loading