Skip to content

Commit fe3635e

Browse files
committed
remove requirement that Amazon.Lambda.RuntimeSupport make InternalsVisibileTo Amazon.Lambda.AspNetCorServer.Hosting
1 parent 62367b7 commit fe3635e

3 files changed

Lines changed: 34 additions & 27 deletions

File tree

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

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Text.Json.Serialization;
99
using Amazon.Lambda.APIGatewayEvents;
1010
using Amazon.Lambda.ApplicationLoadBalancerEvents;
11+
using Amazon.Lambda.Core;
1112
using Amazon.Lambda.RuntimeSupport;
1213
using Amazon.Lambda.RuntimeSupport.Helpers;
1314
using Microsoft.AspNetCore.WebUtilities;
@@ -87,30 +88,36 @@ internal async Task Execute(HttpClient client)
8788
}
8889
}
8990

90-
private static class SnapstartHelperLambdaRequests
91+
private class HelperLambdaContext : ILambdaContext, ICognitoIdentity, IClientContext
9192
{
92-
private static readonly InternalLogger _logger = InternalLogger.GetDefaultLogger();
93-
94-
private static readonly RuntimeApiHeaders _fakeRuntimeApiHeaders = new(new Dictionary<string, IEnumerable<string>>
95-
{
96-
{ RuntimeApiHeaders.HeaderAwsRequestId, new List<string>() },
97-
{ RuntimeApiHeaders.HeaderTraceId, new List<string>() },
98-
{ RuntimeApiHeaders.HeaderClientContext, new List<string>() },
99-
{ RuntimeApiHeaders.HeaderCognitoIdentity, new List<string>() },
100-
{ RuntimeApiHeaders.HeaderDeadlineMs, new List<string>() },
101-
{ RuntimeApiHeaders.HeaderInvokedFunctionArn, new List<string>() },
102-
});
93+
private LambdaEnvironment _lambdaEnvironment = new ();
94+
95+
public string TraceId => string.Empty;
96+
public string AwsRequestId => string.Empty;
97+
public IClientContext ClientContext => this;
98+
public string FunctionName => _lambdaEnvironment.FunctionName;
99+
public string FunctionVersion => _lambdaEnvironment.FunctionVersion;
100+
public ICognitoIdentity Identity => this;
101+
public string InvokedFunctionArn => string.Empty;
102+
public ILambdaLogger Logger => null;
103+
public string LogGroupName => _lambdaEnvironment.LogGroupName;
104+
public string LogStreamName => _lambdaEnvironment.LogStreamName;
105+
public int MemoryLimitInMB => 128;
106+
public TimeSpan RemainingTime => TimeSpan.FromMilliseconds(100);
107+
public string IdentityId { get; }
108+
public string IdentityPoolId { get; }
109+
public IDictionary<string, string> Environment { get; } = new Dictionary<string, string>();
110+
public IClientApplication Client { get; }
111+
public IDictionary<string, string> Custom { get; } = new Dictionary<string, string>();
112+
}
103113

114+
private static class SnapstartHelperLambdaRequests
115+
{
104116
public static async Task ExecuteSnapstartInitRequests(string jsonRequest, int times, HandlerWrapper handlerWrapper)
105117
{
106-
var dummyRequest = new InvocationRequest
107-
{
108-
InputStream = new MemoryStream(Encoding.UTF8.GetBytes(jsonRequest)),
109-
LambdaContext = new LambdaContext(
110-
_fakeRuntimeApiHeaders,
111-
new LambdaEnvironment(),
112-
new SimpleLoggerWriter())
113-
};
118+
var dummyRequest = new InvocationRequest(
119+
new MemoryStream(Encoding.UTF8.GetBytes(jsonRequest)),
120+
new HelperLambdaContext());
114121

115122
for (var i = 0; i < times; i++)
116123
{
@@ -121,7 +128,6 @@ public static async Task ExecuteSnapstartInitRequests(string jsonRequest, int ti
121128
catch (Exception e)
122129
{
123130
Console.WriteLine("StartAsync: " + e.Message + e.StackTrace);
124-
_logger.LogError(e, "StartAsync: Custom Warmup Failure: " + e.Message + e.StackTrace);
125131
}
126132
}
127133
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@
2323
<SignAssembly>true</SignAssembly>
2424
</PropertyGroup>
2525

26-
<ItemGroup>
27-
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
28-
<_Parameter1>Amazon.Lambda.AspNetCoreServer.Hosting, PublicKey="0024000004800000940000000602000000240000525341310004000001000100db5f59f098d27276c7833875a6263a3cc74ab17ba9a9df0b52aedbe7252745db7274d5271fd79c1f08f668ecfa8eaab5626fa76adc811d3c8fc55859b0d09d3bc0a84eecd0ba891f2b8a2fc55141cdcc37c2053d53491e650a479967c3622762977900eddbf1252ed08a2413f00a28f3a0752a81203f03ccb7f684db373518b4"</_Parameter1>
29-
</AssemblyAttribute>
30-
</ItemGroup>
31-
3226
<PropertyGroup Condition=" '$(ExecutableOutputType)'=='true' ">
3327
<OutputType>Exe</OutputType>
3428
</PropertyGroup>

Libraries/src/Amazon.Lambda.RuntimeSupport/Client/InvocationRequest.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ public class InvocationRequest : IDisposable
3535

3636
internal InvocationRequest() { }
3737

38+
/// <inheritdoc cref="InvocationRequest"/>>
39+
public InvocationRequest(Stream inputStream, ILambdaContext lambdaContext)
40+
{
41+
InputStream = inputStream;
42+
LambdaContext = lambdaContext;
43+
}
44+
3845
public void Dispose()
3946
{
4047
InputStream?.Dispose();

0 commit comments

Comments
 (0)