pub struct SimulatorBuilder { /* private fields */ }Expand description
Builder for creating a Lambda runtime simulator.
§Examples
use lambda_simulator::Simulator;
use std::time::Duration;
let simulator = Simulator::builder()
.invocation_timeout(Duration::from_secs(30))
.function_name("my-function")
.build()
.await?;Implementations§
Source§impl SimulatorBuilder
impl SimulatorBuilder
Sourcepub fn invocation_timeout(self, timeout: Duration) -> Self
pub fn invocation_timeout(self, timeout: Duration) -> Self
Sets the invocation timeout.
This timeout is used to calculate the Lambda-Runtime-Deadline-Ms header
sent to the runtime. However, timeout enforcement is not yet implemented
in Phase 1 - invocations will not be automatically terminated.
Sourcepub fn init_timeout(self, timeout: Duration) -> Self
pub fn init_timeout(self, timeout: Duration) -> Self
Sets the initialization timeout.
Note: Timeout enforcement is not yet implemented in Phase 1.
Sourcepub fn function_name(self, name: impl Into<String>) -> Self
pub fn function_name(self, name: impl Into<String>) -> Self
Sets the function name.
Sourcepub fn function_version(self, version: impl Into<String>) -> Self
pub fn function_version(self, version: impl Into<String>) -> Self
Sets the function version.
Sourcepub fn memory_size_mb(self, memory: u32) -> Self
pub fn memory_size_mb(self, memory: u32) -> Self
Sets the function memory size in MB.
Sourcepub fn handler(self, handler: impl Into<String>) -> Self
pub fn handler(self, handler: impl Into<String>) -> Self
Sets the function handler name.
This is used in extension registration responses and the _HANDLER
environment variable.
Sourcepub fn region(self, region: impl Into<String>) -> Self
pub fn region(self, region: impl Into<String>) -> Self
Sets the AWS region.
This is used for AWS_REGION and AWS_DEFAULT_REGION environment
variables, as well as ARN construction.
Default: “us-east-1”
Sourcepub fn account_id(self, account_id: impl Into<String>) -> Self
pub fn account_id(self, account_id: impl Into<String>) -> Self
Sets the AWS account ID.
This is used in extension registration responses and ARN construction.
Sourcepub fn port(self, port: u16) -> Self
pub fn port(self, port: u16) -> Self
Sets the port to bind to. If not specified, a random available port will be used.
Sourcepub fn extension_ready_timeout(self, timeout: Duration) -> Self
pub fn extension_ready_timeout(self, timeout: Duration) -> Self
Sets the timeout for waiting for extensions to be ready.
After the runtime completes an invocation, the simulator will wait up to
this duration for all extensions to signal readiness by polling /next.
If the timeout expires, the simulator proceeds anyway.
Default: 2 seconds
Sourcepub fn shutdown_timeout(self, timeout: Duration) -> Self
pub fn shutdown_timeout(self, timeout: Duration) -> Self
Sets the timeout for graceful shutdown.
During graceful shutdown, extensions subscribed to SHUTDOWN events have this amount of time to complete their cleanup work and signal readiness. If the timeout expires, shutdown proceeds anyway.
Default: 2 seconds
Sourcepub fn freeze_mode(self, mode: FreezeMode) -> Self
pub fn freeze_mode(self, mode: FreezeMode) -> Self
Sets the freeze mode for process freezing simulation.
When set to FreezeMode::Process, the simulator will send SIGSTOP/SIGCONT
signals to simulate Lambda’s freeze/thaw behaviour. This requires a runtime
PID to be configured via runtime_pid().
§Platform Support
Process freezing is only supported on Unix platforms. On other platforms,
FreezeMode::Process will fail at build time.
§Examples
use lambda_simulator::{Simulator, FreezeMode};
let simulator = Simulator::builder()
.freeze_mode(FreezeMode::Process)
.runtime_pid(12345)
.build()
.await?;Sourcepub fn runtime_pid(self, pid: u32) -> Self
pub fn runtime_pid(self, pid: u32) -> Self
Sets the PID of the runtime process for freeze/thaw simulation.
This is required when using FreezeMode::Process. The simulator will
send SIGSTOP to this process after each invocation response is fully
sent, and SIGCONT when a new invocation is enqueued.
§Examples
use lambda_simulator::{Simulator, FreezeMode};
use std::process;
// Use current process PID (for testing)
let simulator = Simulator::builder()
.freeze_mode(FreezeMode::Process)
.runtime_pid(process::id())
.build()
.await?;Sourcepub fn extension_pids(self, pids: Vec<u32>) -> Self
pub fn extension_pids(self, pids: Vec<u32>) -> Self
Sets the PIDs of extension processes for freeze/thaw simulation.
In real AWS Lambda, the entire execution environment is frozen between invocations, including all extension processes. Use this method to register extension PIDs that should be frozen along with the runtime.
§Examples
use lambda_simulator::{Simulator, FreezeMode};
let simulator = Simulator::builder()
.freeze_mode(FreezeMode::Process)
.runtime_pid(12345)
.extension_pids(vec![12346, 12347])
.build()
.await?;