Skip to content

Commit c5ac8ab

Browse files
committed
inline SnapstartHelperLambdaRequest
1 parent a73062e commit c5ac8ab

File tree

5 files changed

+60
-61
lines changed

5 files changed

+60
-61
lines changed

Libraries/src/Amazon.Lambda.AspNetCoreServer.Hosting/Amazon.Lambda.AspNetCoreServer.Hosting.csproj

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
<None Include="README.md" Pack="true" PackagePath="\" />
2222
</ItemGroup>
2323

24+
<PropertyGroup>
25+
<!--This assembly contains some internal methods that need to be accessed by the Amazon.Lambda.Annotations.SourceGenerator assembly.
26+
Both these assemblies need to be strongly signed for the InternalsVisibleTo attribute to take effect.-->
27+
<AssemblyOriginatorKeyFile>..\..\..\buildtools\public.snk</AssemblyOriginatorKeyFile>
28+
<SignAssembly>true</SignAssembly>
29+
</PropertyGroup>
2430

2531
<ItemGroup>
2632
<ProjectReference Include="..\Amazon.Lambda.Core\Amazon.Lambda.Core.csproj" />

Libraries/src/Amazon.Lambda.AspNetCoreServer.Hosting/Internal/LambdaRuntimeSupportServer.cs

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
using System.Diagnostics.CodeAnalysis;
2-
using System.Text;
3-
using System.Text.Json;
42
using Amazon.Lambda.AspNetCoreServer.Internal;
53
using Amazon.Lambda.Core;
64
using Amazon.Lambda.RuntimeSupport;
7-
using Amazon.Lambda.RuntimeSupport.Helpers;
85
using Microsoft.AspNetCore.Hosting.Server;
96
using Microsoft.Extensions.DependencyInjection;
107

@@ -23,7 +20,6 @@ public abstract class LambdaRuntimeSupportServer : LambdaServer
2320

2421
internal ILambdaSerializer Serializer;
2522

26-
2723
/// <summary>
2824
/// Creates an instance on the LambdaRuntimeSupportServer
2925
/// </summary>

Libraries/src/Amazon.Lambda.AspNetCoreServer.Hosting/Internal/LambdaSnapstartExecuteRequestsBeforeSnapshotHelper.cs

+41-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Diagnostics.CodeAnalysis;
55
using System.Net;
6+
using System.Text;
67
using System.Text.Json;
78
using Amazon.Lambda.APIGatewayEvents;
89
using Amazon.Lambda.RuntimeSupport;
@@ -61,7 +62,6 @@ public void RegisterInitializerRequests(HandlerWrapper handlerWrapper)
6162
{
6263
var json = JsonSerializer.Serialize(req);
6364

64-
// TODO - inline
6565
await SnapstartHelperLambdaRequests.ExecuteSnapstartInitRequests(json, times: 5, handlerWrapper);
6666
}
6767
});
@@ -88,6 +88,46 @@ internal async Task Execute(HttpClient client)
8888
}
8989
}
9090

91+
private static class SnapstartHelperLambdaRequests
92+
{
93+
private static InternalLogger _logger = InternalLogger.GetDefaultLogger();
94+
95+
private static readonly RuntimeApiHeaders _fakeRuntimeApiHeaders = new(new Dictionary<string, IEnumerable<string>>
96+
{
97+
{ RuntimeApiHeaders.HeaderAwsRequestId, new List<string>() },
98+
{ RuntimeApiHeaders.HeaderTraceId, new List<string>() },
99+
{ RuntimeApiHeaders.HeaderClientContext, new List<string>() },
100+
{ RuntimeApiHeaders.HeaderCognitoIdentity, new List<string>() },
101+
{ RuntimeApiHeaders.HeaderDeadlineMs, new List<string>() },
102+
{ RuntimeApiHeaders.HeaderInvokedFunctionArn, new List<string>() },
103+
});
104+
105+
public static async Task ExecuteSnapstartInitRequests(string jsonRequest, int times, HandlerWrapper handlerWrapper)
106+
{
107+
var dummyRequest = new InvocationRequest
108+
{
109+
InputStream = new MemoryStream(Encoding.UTF8.GetBytes(jsonRequest)),
110+
LambdaContext = new LambdaContext(
111+
_fakeRuntimeApiHeaders,
112+
new LambdaEnvironment(),
113+
new SimpleLoggerWriter())
114+
};
115+
116+
for (var i = 0; i < times; i++)
117+
{
118+
try
119+
{
120+
_ = await handlerWrapper.Handler.Invoke(dummyRequest);
121+
}
122+
catch (Exception e)
123+
{
124+
Console.WriteLine("StartAsync: " + e.Message + e.StackTrace);
125+
_logger.LogError(e, "StartAsync: Custom Warmup Failure: " + e.Message + e.StackTrace);
126+
}
127+
}
128+
}
129+
}
130+
91131
private class LambdaSnapstartInitializerHttpMessageHandler : HttpMessageHandler
92132
{
93133
private LambdaEventSource _lambdaEventSource;

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

+13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616
<LangVersion>9.0</LangVersion>
1717
</PropertyGroup>
1818

19+
<PropertyGroup>
20+
<!--This assembly contains some internal methods that need to be accessed by the Amazon.Lambda.Annotations.SourceGenerator assembly.
21+
Both these assemblies need to be strongly signed for the InternalsVisibleTo attribute to take effect.-->
22+
<AssemblyOriginatorKeyFile>..\..\..\buildtools\public.snk</AssemblyOriginatorKeyFile>
23+
<SignAssembly>true</SignAssembly>
24+
</PropertyGroup>
25+
26+
<ItemGroup>
27+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
28+
<_Parameter1>Amazon.Lambda.AspNetCoreServer.Hosting, PublicKey="0024000004800000940000000602000000240000525341310004000001000100db5f59f098d27276c7833875a6263a3cc74ab17ba9a9df0b52aedbe7252745db7274d5271fd79c1f08f668ecfa8eaab5626fa76adc811d3c8fc55859b0d09d3bc0a84eecd0ba891f2b8a2fc55141cdcc37c2053d53491e650a479967c3622762977900eddbf1252ed08a2413f00a28f3a0752a81203f03ccb7f684db373518b4"</_Parameter1>
29+
</AssemblyAttribute>
30+
</ItemGroup>
31+
1932
<PropertyGroup Condition=" '$(ExecutableOutputType)'=='true' ">
2033
<OutputType>Exe</OutputType>
2134
</PropertyGroup>

Libraries/src/Amazon.Lambda.RuntimeSupport/Helpers/SnapstartHelperLambdaRequests.cs

-56
This file was deleted.

0 commit comments

Comments
 (0)