88using System . Text . Json . Serialization ;
99using Amazon . Lambda . APIGatewayEvents ;
1010using Amazon . Lambda . ApplicationLoadBalancerEvents ;
11+ using Amazon . Lambda . Core ;
1112using Amazon . Lambda . RuntimeSupport ;
1213using Amazon . Lambda . RuntimeSupport . Helpers ;
1314using 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 }
0 commit comments