Skip to content

Commit c1cf0c5

Browse files
authoredApr 27, 2023
feat: Pull upstream changes 2023/04 (#87)
1 parent a08886c commit c1cf0c5

File tree

122 files changed

+6845
-2726
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+6845
-2726
lines changed
 

‎cmd/aws-lambda-rie/handlers.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import (
1414
"strings"
1515
"time"
1616

17+
"go.amzn.com/lambda/core/statejson"
1718
"go.amzn.com/lambda/interop"
1819
"go.amzn.com/lambda/rapidcore"
20+
"go.amzn.com/lambda/rapidcore/env"
1921

2022
"github.com/google/uuid"
2123

@@ -27,6 +29,19 @@ type Sandbox interface {
2729
Invoke(responseWriter http.ResponseWriter, invoke *interop.Invoke) error
2830
}
2931

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+
3045
var initDone bool
3146

3247
func GetenvWithDefault(key string, defaultValue string) string {
@@ -57,7 +72,7 @@ func printEndReports(invokeId string, initDuration string, memorySize string, in
5772
invokeId, invokeDuration, math.Ceil(invokeDuration), memorySize, memorySize)
5873
}
5974

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) {
6176
log.Debugf("invoke: -> %s %s %v", r.Method, r.URL, r.Header)
6277
bodyBytes, err := ioutil.ReadAll(r.Body)
6378
if err != nil {
@@ -80,7 +95,7 @@ func InvokeHandler(w http.ResponseWriter, r *http.Request, sandbox Sandbox) {
8095

8196
if !initDone {
8297

83-
initStart, initEnd := InitHandler(sandbox, functionVersion, timeout)
98+
initStart, initEnd := InitHandler(sandbox, functionVersion, timeout, bs)
8499

85100
// Calculate InitDuration
86101
initTimeMS := math.Min(float64(initEnd.Sub(initStart).Nanoseconds()),
@@ -99,7 +114,6 @@ func InvokeHandler(w http.ResponseWriter, r *http.Request, sandbox Sandbox) {
99114
TraceID: r.Header.Get("X-Amzn-Trace-Id"),
100115
LambdaSegmentID: r.Header.Get("X-Amzn-Segment-Id"),
101116
Payload: bytes.NewReader(bodyBytes),
102-
CorrelationID: "invokeCorrelationID",
103117
}
104118
fmt.Println("START RequestId: " + invokePayload.ID + " Version: " + functionVersion)
105119

@@ -166,7 +180,7 @@ func InvokeHandler(w http.ResponseWriter, r *http.Request, sandbox Sandbox) {
166180
w.Write(invokeResp.Body)
167181
}
168182

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) {
170184
additionalFunctionEnvironmentVariables := map[string]string{}
171185

172186
// 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
189203
// pass to rapid
190204
sandbox.Init(&interop.Init{
191205
Handler: GetenvWithDefault("AWS_LAMBDA_FUNCTION_HANDLER", os.Getenv("_HANDLER")),
192-
CorrelationID: "initCorrelationID",
193206
AwsKey: os.Getenv("AWS_ACCESS_KEY_ID"),
194207
AwsSecret: os.Getenv("AWS_SECRET_ACCESS_KEY"),
195208
AwsSession: os.Getenv("AWS_SESSION_TOKEN"),
196209
XRayDaemonAddress: "0.0.0.0:0", // TODO
197210
FunctionName: GetenvWithDefault("AWS_LAMBDA_FUNCTION_NAME", "test_function"),
198211
FunctionVersion: functionVersion,
199-
212+
RuntimeInfo: interop.RuntimeInfo{
213+
ImageJSON: "{}",
214+
Arn: "",
215+
Version: ""},
200216
CustomerEnvironmentVariables: additionalFunctionEnvironmentVariables,
217+
SandboxType: interop.SandboxClassic,
218+
Bootstrap: bs,
219+
EnvironmentVariables: env.NewEnvironment(),
201220
}, timeout*1000)
202221
initEnd := time.Now()
203222
return initStart, initEnd

‎cmd/aws-lambda-rie/http.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ import (
77
"net/http"
88

99
log "github.com/sirupsen/logrus"
10+
"go.amzn.com/lambda/interop"
11+
"go.amzn.com/lambda/rapidcore"
1012
)
1113

12-
func startHTTPServer(ipport string, sandbox Sandbox) {
14+
func startHTTPServer(ipport string, sandbox *rapidcore.SandboxBuilder, bs interop.Bootstrap) {
1315
srv := &http.Server{
1416
Addr: ipport,
1517
}
1618

1719
// Pass a channel
1820
http.HandleFunc("/2015-03-31/functions/function/invocations", func(w http.ResponseWriter, r *http.Request) {
19-
InvokeHandler(w, r, sandbox)
21+
InvokeHandler(w, r, sandbox.LambdaInvokeAPI(), bs)
2022
})
2123

2224
// go routine (main thread waits)

0 commit comments

Comments
 (0)