Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion cmd/aws-lambda-rie/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type options struct {
InitCachingEnabled bool `long:"enable-init-caching" description:"Enable support for Init Caching"`
// 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
RuntimeAPIAddress string `long:"runtime-api-address" description:"The address of the AWS Lambda Runtime API to communicate with the Lambda execution environment."`
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."`
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. Can also be set by the environment variable 'RUNTIME_INTERFACE_EMULATOR_ADDRESS'."`
}

func main() {
Expand All @@ -49,6 +49,14 @@ func main() {

rapidcore.SetLogLevel(logLevel)

// Handle RuntimeInterfaceEmulatorAddress environment variable
// If CLI flag not provided, check environment variable
if opts.RuntimeInterfaceEmulatorAddress == "0.0.0.0:8080" {
if envAddress, envAddressSet := os.LookupEnv("RUNTIME_INTERFACE_EMULATOR_ADDRESS"); envAddressSet {
opts.RuntimeInterfaceEmulatorAddress = envAddress
}
}

if opts.RuntimeAPIAddress != "" {
_, _, err := net.SplitHostPort(opts.RuntimeAPIAddress)

Expand Down
24 changes: 24 additions & 0 deletions test/integration/local_lambda/test_end_to_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,30 @@ def test_port_override(self):
self.assertEqual(b'"My lambda ran succesfully"', r.content)


def test_runtime_interface_emulator_address_env_var(self):
image, rie, image_name = self.tagged_name("rie_address_env_var")

# Use port 8081 inside the container and set via environment variable instead of CLI flag
params = f"--name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8081 -e RUNTIME_INTERFACE_EMULATOR_ADDRESS=0.0.0.0:8081 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.success_handler"

with self.create_container(params, image):
r = self.invoke_function()

self.assertEqual(b'"My lambda ran succesfully"', r.content)


def test_runtime_interface_emulator_address_cli_precedence(self):
image, rie, image_name = self.tagged_name("rie_address_cli_precedence")

# Set environment variable but override with CLI flag - CLI should take precedence
params = f"--name {image} -d -v {self.path_to_binary}:/local-lambda-runtime-server -p {self.PORT}:8082 -e RUNTIME_INTERFACE_EMULATOR_ADDRESS=0.0.0.0:8080 --entrypoint /local-lambda-runtime-server/{rie} {image_name} {DEFAULT_1P_ENTRYPOINT} main.success_handler --runtime-interface-emulator-address 0.0.0.0:8082"

with self.create_container(params, image):
r = self.invoke_function()

self.assertEqual(b'"My lambda ran succesfully"', r.content)


def test_custom_client_context(self):
image, rie, image_name = self.tagged_name("custom_client_context")

Expand Down