Skip to content

Commit 5d7c7ec

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 8562f80 commit 5d7c7ec

File tree

178 files changed

+536
-464
lines changed

Some content is hidden

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

178 files changed

+536
-464
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
}

go.mod

Lines changed: 8 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

@@ -13,6 +13,13 @@ require (
1313
github.com/google/uuid v1.6.0
1414
github.com/jessevdk/go-flags v1.5.0
1515
github.com/shirou/gopsutil v2.19.10+incompatible
16+
github.com/aws/aws-lambda-go v1.46.0
17+
github.com/go-chi/chi v1.5.5
18+
github.com/go-chi/chi/v5 v5.2.2
19+
github.com/google/uuid v1.6.0
20+
github.com/jessevdk/go-flags v1.5.0
21+
github.com/orcaman/concurrent-map v1.0.0
22+
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
1623
github.com/sirupsen/logrus v1.9.3
1724
github.com/stretchr/testify v1.9.0
1825
golang.org/x/sync v0.12.0
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
)
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) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package core
55

66
import (
77
"errors"
8+
89
"github.com/google/uuid"
910
)
1011

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
package core
55

66
import (
7+
"testing"
8+
79
"github.com/google/uuid"
810
"github.com/stretchr/testify/require"
9-
"testing"
1011
)
1112

1213
func TestExternalAgentsMapLookupByName(t *testing.T) {

0 commit comments

Comments
 (0)