diff --git a/cmd/aws-lambda-rie/main.go b/cmd/aws-lambda-rie/main.go index bd15402..3653439 100644 --- a/cmd/aws-lambda-rie/main.go +++ b/cmd/aws-lambda-rie/main.go @@ -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() { @@ -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) diff --git a/test/integration/local_lambda/test_end_to_end.py b/test/integration/local_lambda/test_end_to_end.py index d564bb1..24d71a5 100644 --- a/test/integration/local_lambda/test_end_to_end.py +++ b/test/integration/local_lambda/test_end_to_end.py @@ -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")