Skip to content

Commit baf52d0

Browse files
authored
Rename Amazon.Lambda.RuntimeSupport to Amazon.Lambda.RuntimeSupport.TestTool for Lambda Test Tool (#2270)
Address Aspire GitHub issue aws/integrations-on-dotnet-aspire-for-aws#138
1 parent 91dbc04 commit baf52d0

File tree

7 files changed

+66
-9
lines changed

7 files changed

+66
-9
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"Projects": [
3+
{
4+
"Name": "Amazon.Lambda.Core",
5+
"Type": "Patch",
6+
"ChangelogMessages": [
7+
"Add the InternalsVisibleToAttribute to the renamed version of Amazon.Lambda.RuntimeSupport embedded with the Lambda Test Tool"
8+
]
9+
},
10+
{
11+
"Name": "Amazon.Lambda.RuntimeSupport",
12+
"Type": "Patch",
13+
"ChangelogMessages": [
14+
"Add defensive checks for scenarios where a Lambda function uses an older Amazon.Lambda.Core together with the renamed Amazon.Lambda.RuntimeSupport.TestTool assembly embedded in the Lambda Test Tool"
15+
]
16+
},
17+
{
18+
"Name": "Amazon.Lambda.TestTool",
19+
"Type": "Minor",
20+
"ChangelogMessages": [
21+
"Rename embedded Amazon.Lambda.RuntimeSupport assembly to Amazon.Lambda.RuntimeSupport.TestTool to avoid conflicts with Lambda function that might include Amazon.Lambda.RuntimeSupport"
22+
]
23+
}
24+
]
25+
}

Libraries/src/Amazon.Lambda.Core/Amazon.Lambda.Core.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
1919
<_Parameter1>Amazon.Lambda.RuntimeSupport, PublicKey="0024000004800000940000000602000000240000525341310004000001000100db5f59f098d27276c7833875a6263a3cc74ab17ba9a9df0b52aedbe7252745db7274d5271fd79c1f08f668ecfa8eaab5626fa76adc811d3c8fc55859b0d09d3bc0a84eecd0ba891f2b8a2fc55141cdcc37c2053d53491e650a479967c3622762977900eddbf1252ed08a2413f00a28f3a0752a81203f03ccb7f684db373518b4"</_Parameter1>
2020
</AssemblyAttribute>
21+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
22+
<_Parameter1>Amazon.Lambda.RuntimeSupport.TestTool, PublicKey="0024000004800000940000000602000000240000525341310004000001000100db5f59f098d27276c7833875a6263a3cc74ab17ba9a9df0b52aedbe7252745db7274d5271fd79c1f08f668ecfa8eaab5626fa76adc811d3c8fc55859b0d09d3bc0a84eecd0ba891f2b8a2fc55141cdcc37c2053d53491e650a479967c3622762977900eddbf1252ed08a2413f00a28f3a0752a81203f03ccb7f684db373518b4"</_Parameter1>
23+
</AssemblyAttribute>
2124
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
2225
<_Parameter1>Amazon.Lambda.RuntimeSupport.UnitTests, PublicKey="0024000004800000940000000602000000240000525341310004000001000100db5f59f098d27276c7833875a6263a3cc74ab17ba9a9df0b52aedbe7252745db7274d5271fd79c1f08f668ecfa8eaab5626fa76adc811d3c8fc55859b0d09d3bc0a84eecd0ba891f2b8a2fc55141cdcc37c2053d53491e650a479967c3622762977900eddbf1252ed08a2413f00a28f3a0752a81203f03ccb7f684db373518b4"</_Parameter1>
2326
</AssemblyAttribute>

Libraries/src/Amazon.Lambda.RuntimeSupport/Amazon.Lambda.RuntimeSupport.csproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<Version>1.14.1</Version>
88
<Description>Provides a bootstrap and Lambda Runtime API Client to help you to develop custom .NET Core Lambda Runtimes.</Description>
99
<AssemblyTitle>Amazon.Lambda.RuntimeSupport</AssemblyTitle>
10-
<AssemblyName>Amazon.Lambda.RuntimeSupport</AssemblyName>
1110
<PackageId>Amazon.Lambda.RuntimeSupport</PackageId>
1211
<PackageTags>AWS;Amazon;Lambda</PackageTags>
1312
<PackageReadmeFile>README.md</PackageReadmeFile>
@@ -24,6 +23,13 @@
2423
<CheckEolTargetFramework>false</CheckEolTargetFramework>
2524
</PropertyGroup>
2625

26+
<PropertyGroup Condition=" '$(AlternateAssemblyName)'!='' ">
27+
<AssemblyName>$(AlternateAssemblyName)</AssemblyName>
28+
</PropertyGroup>
29+
<PropertyGroup Condition=" '$(AlternateAssemblyName)'=='' ">
30+
<AssemblyName>Amazon.Lambda.RuntimeSupport</AssemblyName>
31+
</PropertyGroup>
32+
2733
<PropertyGroup Condition=" '$(ExecutableOutputType)'=='true' ">
2834
<OutputType>Exe</OutputType>
2935
<DefineConstants>$(DefineConstants);ExecutableOutputType</DefineConstants>

Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/LambdaBootstrap.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,18 @@ internal LambdaBootstrap(HttpClient httpClient, LambdaBootstrapHandler handler,
235235
{
236236
registry = SnapstartHelperCopySnapshotCallbacksIsolated.CopySnapshotCallbacks();
237237
}
238+
catch (MethodAccessException ex)
239+
{
240+
// This would happen with the Lambda test tool when the Amazon.Lambda.RuntimeSupport assembly
241+
// was renamed when embedded into the test tool. The renamed assembly would cause this error
242+
// since older versions Amazon.Lambda.Core used in the customer's function would not have provided
243+
// access to the internals for the renamed assembly version.
244+
Client.ConsoleLogger.FormattedWriteLine(
245+
Amazon.Lambda.RuntimeSupport.Helpers.LogLevelLoggerWriter.LogLevel.Error.ToString(),
246+
"Failed to retrieve snapshot hooks from Amazon.Lambda.Core.SnapshotRestore, " +
247+
$"this can be fixed by updating the version of Amazon.Lambda.Core: {ex}",
248+
null);
249+
}
238250
catch (TypeLoadException ex)
239251
{
240252
Client.ConsoleLogger.FormattedWriteLine(
@@ -441,14 +453,24 @@ private void SetInvocationTraceId(string traceId)
441453
{
442454
TraceProviderIsolated.SetCurrentTraceId(traceId);
443455
}
456+
catch (MethodAccessException)
457+
{
458+
// This would happen with the Lambda test tool when the Amazon.Lambda.RuntimeSupport assembly
459+
// was renamed when embedded into the test tool. The renamed assembly would cause this error
460+
// since older versions Amazon.Lambda.Core used in the customer's function would not have provided
461+
// access to the internals for the renamed assembly version.
462+
_disableTraceProvider = true;
463+
_logger.LogInformation("Failed to set the trace id on Amazon.Lambda.Core.LambdaTraceProvider due to the version of " +
464+
"Amazon.Lambda.Core being provided by Lambda Function being out of date.");
465+
}
444466
catch (TypeLoadException)
445467
{
446468
// Disable attempting to set trace id in the future. If we got a TypeLoadException then setting the
447469
// trace id will never work in the future. Avoid triggering exceptions for every invocation.
448470
_disableTraceProvider = true;
449471
_logger.LogInformation("Failed to set the trace id on Amazon.Lambda.Core.LambdaTraceProvider due to the version of " +
450472
"Amazon.Lambda.Core being provided by Lambda Function being out of date.");
451-
}
473+
}
452474
}
453475
}
454476

Tools/LambdaTestTool-v2/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ Configure the Lambda function to use the test tool:
268268
"LambdaRuntimeClient_FunctionHandler": {
269269
"workingDirectory": ".\\bin\\$(Configuration)\\net8.0",
270270
"commandName": "Executable",
271-
"commandLineArgs": "exec --depsfile ./MyLambdaFunction.deps.json --runtimeconfig ./MyLambdaFunction.runtimeconfig.json %USERPROFILE%/.dotnet/tools/.store/amazon.lambda.testtool/{TEST_TOOL_VERSION}/amazon.lambda.testtool/{TEST_TOOL_VERSION}/content/Amazon.Lambda.RuntimeSupport/{TARGET_FRAMEWORK}/Amazon.Lambda.RuntimeSupport.dll MyLambdaFunction::MyLambdaFunction.Function::Add",
271+
"commandLineArgs": "exec --depsfile ./MyLambdaFunction.deps.json --runtimeconfig ./MyLambdaFunction.runtimeconfig.json %USERPROFILE%/.dotnet/tools/.store/amazon.lambda.testtool/{TEST_TOOL_VERSION}/amazon.lambda.testtool/{TEST_TOOL_VERSION}/content/Amazon.Lambda.RuntimeSupport/{TARGET_FRAMEWORK}/Amazon.Lambda.RuntimeSupport.TestTool.dll MyLambdaFunction::MyLambdaFunction.Function::Add",
272272
"executablePath": "dotnet",
273273
"environmentVariables": {
274274
"AWS_LAMBDA_RUNTIME_API": "localhost:5050/AddLambdaFunction"
@@ -288,7 +288,8 @@ There are three variables you need to update in the launch settings:
288288
2. `{TARGET_FRAMEWORK}` - Replace with your Lambda project's target framework version (e.g., `net8.0` in the example above)
289289
- This appears in two places:
290290
- The working directory: `.\\bin\\$(Configuration)\\{TARGET_FRAMEWORK}`
291-
- The runtime support DLL path: `Amazon.Lambda.RuntimeSupport/{TARGET_FRAMEWORK}/Amazon.Lambda.RuntimeSupport.dll`
291+
- The runtime support DLL path: `Amazon.Lambda.RuntimeSupport/{TARGET_FRAMEWORK}/Amazon.Lambda.RuntimeSupport.TestTool.dll`
292+
- **Note: For the test tool the Amazon.Lambda.RuntimeSupport.dll assembly was renamed to Amazon.Lambda.RuntimeSupport.TestTool.dll to avoid conflicts with versions of Amazon.Lambda.RuntimeSupport used by the Lambda function itself.**
292293

293294
3. `{FUNCTION_HANDLER}` - Replace with your function's handler using the format: `<project_name>::<namespace>.<class>::<method_name>`
294295
- Example: `MyLambdaFunction::MyLambdaFunction.Function::Add`
@@ -341,4 +342,4 @@ The Test Tool provides users with the ability to save Lambda requests for quick
341342

342343
In order to enable saving requests, you will need to provide a storage path during the test tool startup.
343344

344-
You can use the command line argument `--config-storage-path <absolute-path>` to specify the storage path.
345+
You can use the command line argument `--config-storage-path <absolute-path>` to specify the storage path.

Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Amazon.Lambda.TestTool.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
</Target>
4848

4949
<Target Name="PublishRuntimeSupportFiles" DependsOnTargets="GetRuntimeSupportTargetFrameworks" BeforeTargets="Build">
50-
<Exec Command="dotnet publish &quot;$(MSBuildThisFileDirectory)../../../../Libraries/src/Amazon.Lambda.RuntimeSupport/Amazon.Lambda.RuntimeSupport.csproj&quot; -c $(Configuration) -f %(TargetFrameworks.Identity) /p:ExecutableOutputType=true" />
50+
<Exec Command="dotnet publish &quot;$(MSBuildThisFileDirectory)../../../../Libraries/src/Amazon.Lambda.RuntimeSupport/Amazon.Lambda.RuntimeSupport.csproj&quot; -c $(Configuration) -f %(TargetFrameworks.Identity) /p:ExecutableOutputType=true /p:AlternateAssemblyName=Amazon.Lambda.RuntimeSupport.TestTool" />
5151
</Target>
5252

5353
<Target Name="CopyRuntimeSupportFiles" DependsOnTargets="GetRuntimeSupportTargetFrameworks" BeforeTargets="_GetPackageFiles">

Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/PackagingTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ public void VerifyPackageContentsHasRuntimeSupport()
144144
var essentialFiles = new[]
145145
{
146146
$"content/Amazon.Lambda.RuntimeSupport/{framework}/Amazon.Lambda.Core.dll",
147-
$"content/Amazon.Lambda.RuntimeSupport/{framework}/Amazon.Lambda.RuntimeSupport.dll",
148-
$"content/Amazon.Lambda.RuntimeSupport/{framework}/Amazon.Lambda.RuntimeSupport.deps.json",
149-
$"content/Amazon.Lambda.RuntimeSupport/{framework}/Amazon.Lambda.RuntimeSupport.runtimeconfig.json"
147+
$"content/Amazon.Lambda.RuntimeSupport/{framework}/Amazon.Lambda.RuntimeSupport.TestTool.dll",
148+
$"content/Amazon.Lambda.RuntimeSupport/{framework}/Amazon.Lambda.RuntimeSupport.TestTool.deps.json",
149+
$"content/Amazon.Lambda.RuntimeSupport/{framework}/Amazon.Lambda.RuntimeSupport.TestTool.runtimeconfig.json"
150150
};
151151

152152
var missingFiles = essentialFiles.Where(f => !frameworkFiles.Contains(f)).ToList();

0 commit comments

Comments
 (0)