Skip to content

Commit b887544

Browse files
licjungregfurman
authored andcommitted
feat(Multi-tenancy): Add support for multi-tenancy
* Add support for multi-tenancy --------- Co-authored-by: Chengjun Li <>
1 parent 03a88ea commit b887544

File tree

185 files changed

+559
-488
lines changed

Some content is hidden

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

185 files changed

+559
-488
lines changed

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
}

cmd/localstack/awsutil.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ package main
99
import (
1010
"context"
1111
"fmt"
12-
log "github.com/sirupsen/logrus"
13-
"go.amzn.com/lambda/interop"
14-
"go.amzn.com/lambda/rapidcore/env"
15-
"golang.org/x/sys/unix"
1612
"io"
1713
"io/fs"
1814
"math"
@@ -21,6 +17,11 @@ import (
2117
"path/filepath"
2218
"strings"
2319
"time"
20+
21+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/interop"
22+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/rapidcore/env"
23+
log "github.com/sirupsen/logrus"
24+
"golang.org/x/sys/unix"
2425
)
2526

2627
const (

cmd/localstack/custom_interop.go

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

17+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/core/statejson"
18+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/interop"
19+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/rapidcore"
20+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/rapidcore/standalone"
1721
"github.com/go-chi/chi"
1822
log "github.com/sirupsen/logrus"
19-
"go.amzn.com/lambda/core/statejson"
20-
"go.amzn.com/lambda/interop"
21-
"go.amzn.com/lambda/rapidcore"
22-
"go.amzn.com/lambda/rapidcore/standalone"
2323
)
2424

2525
type CustomInteropServer struct {

cmd/localstack/hotreloading.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package main
22

33
import (
4-
"github.com/fsnotify/fsnotify"
5-
log "github.com/sirupsen/logrus"
6-
"go.amzn.com/cmd/localstack/filenotify"
74
"os"
85
"time"
6+
7+
"github.com/aws/aws-lambda-runtime-interface-emulator/cmd/localstack/filenotify"
8+
"github.com/fsnotify/fsnotify"
9+
log "github.com/sirupsen/logrus"
910
)
1011

1112
type ChangeListener struct {

cmd/localstack/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"strings"
1111
"time"
1212

13+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/interop"
14+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/rapidcore"
1315
log "github.com/sirupsen/logrus"
14-
"go.amzn.com/lambda/interop"
15-
"go.amzn.com/lambda/rapidcore"
1616
)
1717

1818
type LsOpts struct {

cmd/localstack/simple_bootstrap.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"os"
99
"path/filepath"
1010

11-
"go.amzn.com/lambda/fatalerror"
12-
"go.amzn.com/lambda/interop"
13-
"go.amzn.com/lambda/rapidcore/env"
11+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/fatalerror"
12+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/interop"
13+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/rapidcore/env"
1414
)
1515

1616
// the type implement a simpler version of the Bootstrap

cmd/localstack/tracer.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package main
33
import (
44
"context"
55
"encoding/json"
6-
"go.amzn.com/lambda/appctx"
7-
"go.amzn.com/lambda/interop"
6+
7+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/appctx"
8+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/interop"
89
)
910

1011
type LocalStackTracer struct {

go.mod

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

33
go 1.25
44

@@ -9,6 +9,7 @@ require (
99
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575
1010
github.com/fsnotify/fsnotify v1.6.0
1111
github.com/go-chi/chi v1.5.5
12+
github.com/go-chi/chi/v5 v5.2.2
1213
github.com/google/uuid v1.6.0
1314
github.com/jessevdk/go-flags v1.5.0
1415
github.com/shirou/gopsutil v2.19.10+incompatible

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4
1717
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
1818
github.com/go-chi/chi v1.5.5 h1:vOB/HbEMt9QqBqErz07QehcOKHaWFtuj87tTDVz2qXE=
1919
github.com/go-chi/chi v1.5.5/go.mod h1:C9JqLr3tIYjDOZpzn+BCuxY8z8vmca43EeMgyZt7irw=
20+
github.com/go-chi/chi/v5 v5.2.2 h1:CMwsvRVTbXVytCk1Wd72Zy1LAsAh9GxMmSNWLHCG618=
21+
github.com/go-chi/chi/v5 v5.2.2/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
2022
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
2123
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
2224
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
File renamed without changes.

0 commit comments

Comments
 (0)