Skip to content

Commit ad5b46f

Browse files
authored
feat(Multi-tenancy): Add support for multi-tenancy
* Add support for multi-tenancy --------- Co-authored-by: Chengjun Li <>
1 parent c17162c commit ad5b46f

File tree

180 files changed

+539
-465
lines changed

Some content is hidden

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

180 files changed

+539
-465
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ DESTINATION_old:= bin/${BINARY_NAME}
1010
DESTINATION_x86_64 := bin/${BINARY_NAME}-x86_64
1111
DESTINATION_arm64 := bin/${BINARY_NAME}-arm64
1212

13-
run_in_docker = docker run --env GOPROXY=direct -v $(shell pwd):/LambdaRuntimeLocal -w /LambdaRuntimeLocal golang:1.24 $(1)
13+
run_in_docker = docker run --env GOPROXY=direct -v $(shell pwd):/LambdaRuntimeLocal -w /LambdaRuntimeLocal golang:1.25 $(1)
1414

1515
compile-with-docker-all:
1616
$(call run_in_docker, make compile-lambda-linux-all)

cmd/aws-lambda-rie/main.go

Lines changed: 2 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -4,151 +4,9 @@
44
package main
55

66
import (
7-
"context"
8-
"fmt"
9-
"net"
10-
"os"
11-
"runtime/debug"
12-
13-
"github.com/jessevdk/go-flags"
14-
"go.amzn.com/lambda/interop"
15-
"go.amzn.com/lambda/rapidcore"
16-
17-
log "github.com/sirupsen/logrus"
7+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/rie"
188
)
199

20-
const (
21-
optBootstrap = "/opt/bootstrap"
22-
runtimeBootstrap = "/var/runtime/bootstrap"
23-
)
24-
25-
type options struct {
26-
LogLevel string `long:"log-level" description:"The level of AWS Lambda Runtime Interface Emulator logs to display. Can also be set by the environment variable 'LOG_LEVEL'. Defaults to the value 'info'."`
27-
InitCachingEnabled bool `long:"enable-init-caching" description:"Enable support for Init Caching"`
28-
// Do not have a default value so we do not need to keep it in sync with the default value in lambda/rapidcore/sandbox_builder.go
29-
RuntimeAPIAddress string `long:"runtime-api-address" description:"The address of the AWS Lambda Runtime API to communicate with the Lambda execution environment."`
30-
RuntimeInterfaceEmulatorAddress string `long:"runtime-interface-emulator-address" default:"0.0.0.0:8080" description:"The address for the AWS Lambda Runtime Interface Emulator to accept HTTP request upon."`
31-
}
32-
3310
func main() {
34-
// More frequent GC reduces the tail latencies, equivalent to export GOGC=33
35-
debug.SetGCPercent(33)
36-
37-
opts, args := getCLIArgs()
38-
39-
logLevel := "info"
40-
41-
// If you specify an option by using a parameter on the CLI command line, it overrides any value from either the corresponding environment variable.
42-
//
43-
// https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html
44-
if opts.LogLevel != "" {
45-
logLevel = opts.LogLevel
46-
} else if envLogLevel, envLogLevelSet := os.LookupEnv("LOG_LEVEL"); envLogLevelSet {
47-
logLevel = envLogLevel
48-
}
49-
50-
rapidcore.SetLogLevel(logLevel)
51-
52-
if opts.RuntimeAPIAddress != "" {
53-
_, _, err := net.SplitHostPort(opts.RuntimeAPIAddress)
54-
55-
if err != nil {
56-
log.WithError(err).Fatalf("The command line value for \"--runtime-api-address\" is not a valid network address %q.", opts.RuntimeAPIAddress)
57-
}
58-
}
59-
60-
_, _, err := net.SplitHostPort(opts.RuntimeInterfaceEmulatorAddress)
61-
62-
if err != nil {
63-
log.WithError(err).Fatalf("The command line value for \"--runtime-interface-emulator-address\" is not a valid network address %q.", opts.RuntimeInterfaceEmulatorAddress)
64-
}
65-
66-
bootstrap, handler := getBootstrap(args, opts)
67-
sandbox := rapidcore.
68-
NewSandboxBuilder().
69-
AddShutdownFunc(context.CancelFunc(func() { os.Exit(0) })).
70-
SetExtensionsFlag(true).
71-
SetInitCachingFlag(opts.InitCachingEnabled)
72-
73-
if len(handler) > 0 {
74-
sandbox.SetHandler(handler)
75-
}
76-
77-
if opts.RuntimeAPIAddress != "" {
78-
sandbox.SetRuntimeAPIAddress(opts.RuntimeAPIAddress)
79-
}
80-
81-
sandboxContext, internalStateFn := sandbox.Create()
82-
// Since we have not specified a custom interop server for standalone, we can
83-
// directly reference the default interop server, which is a concrete type
84-
sandbox.DefaultInteropServer().SetSandboxContext(sandboxContext)
85-
sandbox.DefaultInteropServer().SetInternalStateGetter(internalStateFn)
86-
87-
startHTTPServer(opts.RuntimeInterfaceEmulatorAddress, sandbox, bootstrap)
88-
}
89-
90-
func getCLIArgs() (options, []string) {
91-
var opts options
92-
parser := flags.NewParser(&opts, flags.IgnoreUnknown)
93-
args, err := parser.ParseArgs(os.Args)
94-
95-
if err != nil {
96-
log.WithError(err).Fatal("Failed to parse command line arguments:", os.Args)
97-
}
98-
99-
return opts, args
100-
}
101-
102-
func isBootstrapFileExist(filePath string) bool {
103-
file, err := os.Stat(filePath)
104-
return !os.IsNotExist(err) && !file.IsDir()
105-
}
106-
107-
func getBootstrap(args []string, opts options) (interop.Bootstrap, string) {
108-
var bootstrapLookupCmd []string
109-
var handler string
110-
currentWorkingDir := "/var/task" // default value
111-
112-
if len(args) <= 1 {
113-
// set default value to /var/task/bootstrap, but switch to the other options if it doesn't exist
114-
bootstrapLookupCmd = []string{
115-
fmt.Sprintf("%s/bootstrap", currentWorkingDir),
116-
}
117-
118-
if !isBootstrapFileExist(bootstrapLookupCmd[0]) {
119-
var bootstrapCmdCandidates = []string{
120-
optBootstrap,
121-
runtimeBootstrap,
122-
}
123-
124-
for i, bootstrapCandidate := range bootstrapCmdCandidates {
125-
if isBootstrapFileExist(bootstrapCandidate) {
126-
bootstrapLookupCmd = []string{bootstrapCmdCandidates[i]}
127-
break
128-
}
129-
}
130-
}
131-
132-
// handler is used later to set an env var for Lambda Image support
133-
handler = ""
134-
} else if len(args) > 1 {
135-
136-
bootstrapLookupCmd = args[1:]
137-
138-
if cwd, err := os.Getwd(); err == nil {
139-
currentWorkingDir = cwd
140-
}
141-
142-
if len(args) > 2 {
143-
// Assume last arg is the handler
144-
handler = args[len(args)-1]
145-
}
146-
147-
log.Infof("exec '%s' (cwd=%s, handler=%s)", args[1], currentWorkingDir, handler)
148-
149-
} else {
150-
log.Panic("insufficient arguments: bootstrap not provided")
151-
}
152-
153-
return NewSimpleBootstrap(bootstrapLookupCmd, currentWorkingDir), handler
11+
rie.Run()
15412
}

go.mod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
module go.amzn.com
1+
module github.com/aws/aws-lambda-runtime-interface-emulator
22

3-
go 1.24
3+
go 1.25
44

55
require (
66
github.com/aws/aws-lambda-go v1.46.0
7+
github.com/go-chi/chi v1.5.5
78
github.com/go-chi/chi/v5 v5.2.2
89
github.com/google/uuid v1.6.0
910
github.com/jessevdk/go-flags v1.5.0
11+
github.com/orcaman/concurrent-map v1.0.0
12+
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
1013
github.com/sirupsen/logrus v1.9.3
1114
github.com/stretchr/testify v1.9.0
1215
golang.org/x/sync v0.6.0

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@ github.com/aws/aws-lambda-go v1.46.0/go.mod h1:dpMpZgvWx5vuQJfBt0zqBha60q7Dd7Rfg
33
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
44
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
55
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6+
github.com/go-chi/chi v1.5.5 h1:vOB/HbEMt9QqBqErz07QehcOKHaWFtuj87tTDVz2qXE=
7+
github.com/go-chi/chi v1.5.5/go.mod h1:C9JqLr3tIYjDOZpzn+BCuxY8z8vmca43EeMgyZt7irw=
68
github.com/go-chi/chi/v5 v5.2.2 h1:CMwsvRVTbXVytCk1Wd72Zy1LAsAh9GxMmSNWLHCG618=
79
github.com/go-chi/chi/v5 v5.2.2/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
810
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
911
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
1012
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=
1113
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
14+
github.com/orcaman/concurrent-map v1.0.0 h1:I/2A2XPCb4IuQWcQhBhSwGfiuybl/J0ev9HDbW65HOY=
15+
github.com/orcaman/concurrent-map v1.0.0/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI=
1216
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1317
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
18+
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4=
19+
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
1420
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
1521
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
1622
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
File renamed without changes.
File renamed without changes.
File renamed without changes.

lambda/appctx/appctxutil.go renamed to internal/lambda/appctx/appctxutil.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"net/http"
99
"strings"
1010

11-
"go.amzn.com/lambda/fatalerror"
12-
"go.amzn.com/lambda/interop"
11+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/fatalerror"
12+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/interop"
1313

1414
log "github.com/sirupsen/logrus"
1515
)

lambda/appctx/appctxutil_test.go renamed to internal/lambda/appctx/appctxutil_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88
"strings"
99
"testing"
1010

11+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/fatalerror"
1112
"github.com/stretchr/testify/assert"
1213
"github.com/stretchr/testify/require"
13-
"go.amzn.com/lambda/fatalerror"
1414

15-
"go.amzn.com/lambda/interop"
15+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/interop"
1616
)
1717

1818
func runTestRequestWithUserAgent(t *testing.T, userAgent string, expectedRuntimeRelease string) {
File renamed without changes.

0 commit comments

Comments
 (0)