pub struct Proxy {
pub port: Option<u16>,
pub command: Option<Command>,
}
Expand description
This is the high level API for this crate,
which will create a MockLambdaRuntimeApiServer
and a handler process.
You can also use MockLambdaRuntimeApiServer
and LambdaRuntimeApiClient
directly.
§Examples
use aws_lambda_runtime_proxy::Proxy;
// create the proxy server and the handler process using the default configuration
let proxy = Proxy::default().spawn().await.unwrap();
// forward all requests to the real Lambda Runtime API
proxy.server.passthrough().await;
Fields§
§port: Option<u16>
See Self::port
.
command: Option<Command>
See Self::command
.
Implementations§
Source§impl Proxy
impl Proxy
Sourcepub fn default_command() -> Option<Command>
pub fn default_command() -> Option<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 aws_lambda_runtime_proxy::Proxy;
use std::process::Stdio;
// retrieve the default handler command
let mut command = Proxy::default_command().unwrap();
// 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) -> Result<RunningProxy>
pub async fn spawn(self) -> Result<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.