forked from aws/aws-lambda-runtime-interface-emulator
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsandbox.go
More file actions
101 lines (89 loc) · 3.46 KB
/
sandbox.go
File metadata and controls
101 lines (89 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package rapid
import (
"context"
"fmt"
"io"
"go.amzn.com/lambda/appctx"
"go.amzn.com/lambda/core"
"go.amzn.com/lambda/interop"
"go.amzn.com/lambda/logging"
"go.amzn.com/lambda/metering"
"go.amzn.com/lambda/rapi"
"go.amzn.com/lambda/rapi/rendering"
"go.amzn.com/lambda/telemetry"
)
type EnvironmentVariables interface {
AgentExecEnv() []string
RuntimeExecEnv() []string
SetHandler(handler string)
StoreRuntimeAPIEnvironmentVariable(runtimeAPIAddress string)
StoreEnvironmentVariablesFromInit(customerEnv map[string]string,
handler, awsKey, awsSecret, awsSession, funcName, funcVer string)
StoreEnvironmentVariablesFromInitForInitCaching(host string, port int, customerEnv map[string]string, handler, funcName, funcVer, token string)
}
type Sandbox struct {
EnableTelemetryAPI bool
StandaloneMode bool
Bootstrap Bootstrap
InteropServer interop.Server
Tracer telemetry.Tracer
LogsSubscriptionAPI telemetry.LogsSubscriptionAPI
LogsEgressAPI telemetry.LogsEgressAPI
Environment EnvironmentVariables
DebugTailLogger *logging.TailLogWriter
PlatformLogger logging.PlatformLogger
RuntimeStdoutWriter io.Writer
RuntimeStderrWriter io.Writer
PreLoadTimeNs int64
Handler string
SignalCtx context.Context
EventsAPI telemetry.EventsAPI
InitCachingEnabled bool
}
// Start is a public version of start() that exports only configurable parameters
func Start(s *Sandbox) {
appCtx := appctx.NewApplicationContext()
initFlow := core.NewInitFlowSynchronization()
invokeFlow := core.NewInvokeFlowSynchronization()
registrationService := core.NewRegistrationService(initFlow, invokeFlow)
renderingService := rendering.NewRenderingService()
credentialsService := core.NewCredentialsService()
if s.StandaloneMode {
s.InteropServer.SetInternalStateGetter(registrationService.GetInternalStateDescriptor(appCtx))
}
server := rapi.NewServer(RuntimeAPIHost, RuntimeAPIPort, appCtx, registrationService, renderingService, s.EnableTelemetryAPI, s.LogsSubscriptionAPI, s.InitCachingEnabled, credentialsService)
postLoadTimeNs := metering.Monotime()
runtimeAPIAddr := fmt.Sprintf("%s:%d", server.Host(), server.Port())
s.Environment.StoreRuntimeAPIEnvironmentVariable(runtimeAPIAddr)
appctx.StoreInteropServer(appCtx, s.InteropServer)
start(s.SignalCtx, &rapidContext{
server: server,
appCtx: appCtx,
postLoadTimeNs: postLoadTimeNs,
initDone: false,
initFlow: initFlow,
invokeFlow: invokeFlow,
registrationService: registrationService,
renderingService: renderingService,
exitPidChan: make(chan int),
resetChan: make(chan *interop.Reset),
credentialsService: credentialsService,
telemetryAPIEnabled: s.EnableTelemetryAPI,
logsSubscriptionAPI: s.LogsSubscriptionAPI,
logsEgressAPI: s.LogsEgressAPI,
bootstrap: s.Bootstrap,
interopServer: s.InteropServer,
xray: s.Tracer,
environment: s.Environment,
standaloneMode: s.StandaloneMode,
debugTailLogger: s.DebugTailLogger,
platformLogger: s.PlatformLogger,
runtimeStdoutWriter: s.RuntimeStdoutWriter,
runtimeStderrWriter: s.RuntimeStderrWriter,
preLoadTimeNs: s.PreLoadTimeNs,
eventsAPI: s.EventsAPI,
initCachingEnabled: s.InitCachingEnabled,
})
}