Skip to content

Commit 5f17c1c

Browse files
committed
feat: add environment variable support for runtime interface emulator address
Add support for RUNTIME_INTERFACE_EMULATOR_ADDRESS environment variable to configure the emulator address without requiring CLI flags. This enables easier configuration in containerized environments where modifying the entrypoint script is not practical. The implementation follows the same pattern as LOG_LEVEL handling. Features: - Environment variable RUNTIME_INTERFACE_EMULATOR_ADDRESS support - CLI flag takes precedence over environment variable (AWS CLI pattern) - Updated help text to document the environment variable - Added integration tests for environment variable usage - Added test for CLI flag precedence over environment variable Fixes #120
1 parent c17162c commit 5f17c1c

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

cmd/aws-lambda-rie/main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type options struct {
2727
InitCachingEnabled bool `long:"enable-init-caching" description:"Enable support for Init Caching"`
2828
// 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
2929
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."`
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. Can also be set by the environment variable 'RUNTIME_INTERFACE_EMULATOR_ADDRESS'."`
3131
}
3232

3333
func main() {
@@ -49,6 +49,14 @@ func main() {
4949

5050
rapidcore.SetLogLevel(logLevel)
5151

52+
// Handle RuntimeInterfaceEmulatorAddress environment variable
53+
// If CLI flag not provided, check environment variable
54+
if opts.RuntimeInterfaceEmulatorAddress == "0.0.0.0:8080" {
55+
if envAddress, envAddressSet := os.LookupEnv("RUNTIME_INTERFACE_EMULATOR_ADDRESS"); envAddressSet {
56+
opts.RuntimeInterfaceEmulatorAddress = envAddress
57+
}
58+
}
59+
5260
if opts.RuntimeAPIAddress != "" {
5361
_, _, err := net.SplitHostPort(opts.RuntimeAPIAddress)
5462

test/integration/local_lambda/test_end_to_end.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,30 @@ def test_port_override(self):
235235
self.assertEqual(b'"My lambda ran succesfully"', r.content)
236236

237237

238+
def test_runtime_interface_emulator_address_env_var(self):
239+
image, rie, image_name = self.tagged_name("rie_address_env_var")
240+
241+
# Use port 8081 inside the container and set via environment variable instead of CLI flag
242+
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"
243+
244+
with self.create_container(params, image):
245+
r = self.invoke_function()
246+
247+
self.assertEqual(b'"My lambda ran succesfully"', r.content)
248+
249+
250+
def test_runtime_interface_emulator_address_cli_precedence(self):
251+
image, rie, image_name = self.tagged_name("rie_address_cli_precedence")
252+
253+
# Set environment variable but override with CLI flag - CLI should take precedence
254+
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"
255+
256+
with self.create_container(params, image):
257+
r = self.invoke_function()
258+
259+
self.assertEqual(b'"My lambda ran succesfully"', r.content)
260+
261+
238262
def test_custom_client_context(self):
239263
image, rie, image_name = self.tagged_name("custom_client_context")
240264

0 commit comments

Comments
 (0)