Struct aws_lambda_runtime_proxy::Proxy
source · pub struct Proxy {
pub port: Option<u16>,
pub command: Option<Command>,
}
Expand description
Use Proxy::spawn
to create a new proxy server and handler process.
Fields§
§port: Option<u16>
See Self::port
.
command: Option<Command>
See Self::command
.
Implementations§
source§impl Proxy
impl Proxy
sourcepub fn default_command() -> Command
pub fn default_command() -> Command
Create the handler command from the argv[1..]
.
For example if the command of the current process is proxy node --help
then the handler command will be node --help
.
You can modify the handler command and pass it to Self::command
.
§Examples
use lambda_runtime_proxy::Proxy;
use std::process::Stdio;
#[tokio::main]
async fn main {
// retrieve the default handler command
let mut command = Proxy::default_command();
// enhance the handler command
command
// override environment variables for the handler process
.env("KEY", "VALUE")
// pipe the stdout and stderr of the handler process
.stdout(Stdio::piped())
.stderr(Stdio::piped());
Proxy::default()
.command(command)
.spawn().await;
}
sourcepub fn port(self, port: u16) -> Self
pub fn port(self, port: u16) -> Self
Set the port of the proxy server.
If not set, the port will be read from the environment variable AWS_LAMBDA_RUNTIME_PROXY_PORT
,
or default to 3000
.
sourcepub fn command(self, cmd: Command) -> Self
pub fn command(self, cmd: Command) -> Self
Set the command of the handler process.
If not set, the command will be created using Self::default_command
.
sourcepub async fn spawn(self) -> RunningProxy
pub async fn spawn(self) -> RunningProxy
Spawn the proxy server and the handler process.
The handler process will be spawned with the environment variable AWS_LAMBDA_RUNTIME_API
set to the address of the proxy server.