@@ -14,8 +14,10 @@ import (
14
14
"strings"
15
15
"time"
16
16
17
+ "go.amzn.com/lambda/core/statejson"
17
18
"go.amzn.com/lambda/interop"
18
19
"go.amzn.com/lambda/rapidcore"
20
+ "go.amzn.com/lambda/rapidcore/env"
19
21
20
22
"github.com/google/uuid"
21
23
@@ -27,6 +29,19 @@ type Sandbox interface {
27
29
Invoke (responseWriter http.ResponseWriter , invoke * interop.Invoke ) error
28
30
}
29
31
32
+ type InteropServer interface {
33
+ Init (i * interop.Init , invokeTimeoutMs int64 ) error
34
+ AwaitInitialized () error
35
+ FastInvoke (w http.ResponseWriter , i * interop.Invoke , direct bool ) error
36
+ Reserve (id string , traceID , lambdaSegmentID string ) (* rapidcore.ReserveResponse , error )
37
+ Reset (reason string , timeoutMs int64 ) (* statejson.ResetDescription , error )
38
+ AwaitRelease () (* statejson.InternalStateDescription , error )
39
+ Shutdown (shutdown * interop.Shutdown ) * statejson.InternalStateDescription
40
+ InternalState () (* statejson.InternalStateDescription , error )
41
+ CurrentToken () * interop.Token
42
+ Restore (restore * interop.Restore ) error
43
+ }
44
+
30
45
var initDone bool
31
46
32
47
func GetenvWithDefault (key string , defaultValue string ) string {
@@ -57,7 +72,7 @@ func printEndReports(invokeId string, initDuration string, memorySize string, in
57
72
invokeId , invokeDuration , math .Ceil (invokeDuration ), memorySize , memorySize )
58
73
}
59
74
60
- func InvokeHandler (w http.ResponseWriter , r * http.Request , sandbox Sandbox ) {
75
+ func InvokeHandler (w http.ResponseWriter , r * http.Request , sandbox Sandbox , bs interop. Bootstrap ) {
61
76
log .Debugf ("invoke: -> %s %s %v" , r .Method , r .URL , r .Header )
62
77
bodyBytes , err := ioutil .ReadAll (r .Body )
63
78
if err != nil {
@@ -80,7 +95,7 @@ func InvokeHandler(w http.ResponseWriter, r *http.Request, sandbox Sandbox) {
80
95
81
96
if ! initDone {
82
97
83
- initStart , initEnd := InitHandler (sandbox , functionVersion , timeout )
98
+ initStart , initEnd := InitHandler (sandbox , functionVersion , timeout , bs )
84
99
85
100
// Calculate InitDuration
86
101
initTimeMS := math .Min (float64 (initEnd .Sub (initStart ).Nanoseconds ()),
@@ -99,7 +114,6 @@ func InvokeHandler(w http.ResponseWriter, r *http.Request, sandbox Sandbox) {
99
114
TraceID : r .Header .Get ("X-Amzn-Trace-Id" ),
100
115
LambdaSegmentID : r .Header .Get ("X-Amzn-Segment-Id" ),
101
116
Payload : bytes .NewReader (bodyBytes ),
102
- CorrelationID : "invokeCorrelationID" ,
103
117
}
104
118
fmt .Println ("START RequestId: " + invokePayload .ID + " Version: " + functionVersion )
105
119
@@ -166,7 +180,7 @@ func InvokeHandler(w http.ResponseWriter, r *http.Request, sandbox Sandbox) {
166
180
w .Write (invokeResp .Body )
167
181
}
168
182
169
- func InitHandler (sandbox Sandbox , functionVersion string , timeout int64 ) (time.Time , time.Time ) {
183
+ func InitHandler (sandbox Sandbox , functionVersion string , timeout int64 , bs interop. Bootstrap ) (time.Time , time.Time ) {
170
184
additionalFunctionEnvironmentVariables := map [string ]string {}
171
185
172
186
// Add default Env Vars if they were not defined. This is a required otherwise 1p Python2.7, Python3.6, and
@@ -189,15 +203,20 @@ func InitHandler(sandbox Sandbox, functionVersion string, timeout int64) (time.T
189
203
// pass to rapid
190
204
sandbox .Init (& interop.Init {
191
205
Handler : GetenvWithDefault ("AWS_LAMBDA_FUNCTION_HANDLER" , os .Getenv ("_HANDLER" )),
192
- CorrelationID : "initCorrelationID" ,
193
206
AwsKey : os .Getenv ("AWS_ACCESS_KEY_ID" ),
194
207
AwsSecret : os .Getenv ("AWS_SECRET_ACCESS_KEY" ),
195
208
AwsSession : os .Getenv ("AWS_SESSION_TOKEN" ),
196
209
XRayDaemonAddress : "0.0.0.0:0" , // TODO
197
210
FunctionName : GetenvWithDefault ("AWS_LAMBDA_FUNCTION_NAME" , "test_function" ),
198
211
FunctionVersion : functionVersion ,
199
-
212
+ RuntimeInfo : interop.RuntimeInfo {
213
+ ImageJSON : "{}" ,
214
+ Arn : "" ,
215
+ Version : "" },
200
216
CustomerEnvironmentVariables : additionalFunctionEnvironmentVariables ,
217
+ SandboxType : interop .SandboxClassic ,
218
+ Bootstrap : bs ,
219
+ EnvironmentVariables : env .NewEnvironment (),
201
220
}, timeout * 1000 )
202
221
initEnd := time .Now ()
203
222
return initStart , initEnd
0 commit comments