Struct aws_lambda_runtime_proxy::Proxy
source · pub struct Proxy {
pub port: Option<u16>,
pub command: Option<Command>,
}
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;
}
Examples found in repository?
examples/modify_handler_process.rs (line 6)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
async fn main() {
let mut handler = Proxy::default_command()
// capture stdout
.stdout(Stdio::piped())
// override environment variables for the handler process
.env("KEY", "VALUE")
// pass additional arguments to the handler process
.arg("--help")
.spawn()
.unwrap();
// take the stdout
let _stdout = handler.stdout.take().unwrap();
// do something with the stdout
// wait until the handler process exits
handler.wait().await.unwrap();
}
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<ReqBody: Body + Send + 'static>(
self
) -> RunningProxy<ReqBody>
pub async fn spawn<ReqBody: Body + Send + 'static>( self ) -> RunningProxy<ReqBody>
Spawn the proxy server, lambda runtime api client 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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Proxy
impl !RefUnwindSafe for Proxy
impl Send for Proxy
impl Sync for Proxy
impl Unpin for Proxy
impl !UnwindSafe for Proxy
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more