SimulatorBuilder

Struct SimulatorBuilder 

Source
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

Source

pub fn new() -> Self

Creates a new simulator builder with default configuration.

Source

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.

Source

pub fn init_timeout(self, timeout: Duration) -> Self

Sets the initialization timeout.

Note: Timeout enforcement is not yet implemented in Phase 1.

Source

pub fn function_name(self, name: impl Into<String>) -> Self

Sets the function name.

Source

pub fn function_version(self, version: impl Into<String>) -> Self

Sets the function version.

Source

pub fn memory_size_mb(self, memory: u32) -> Self

Sets the function memory size in MB.

Source

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.

Source

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”

Source

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.

Source

pub fn port(self, port: u16) -> Self

Sets the port to bind to. If not specified, a random available port will be used.

Source

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

Source

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

Source

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?;
Source

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?;
Source

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?;
Source

pub async fn build(self) -> SimulatorResult<Simulator>

Builds and starts the simulator.

§Returns

A running simulator instance.

§Errors

Returns an error if:

  • The server fails to start or bind to the specified address.
  • FreezeMode::Process is used on a non-Unix platform.

Trait Implementations§

Source§

impl Debug for SimulatorBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SimulatorBuilder

Source§

fn default() -> SimulatorBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more