Struct RuntimeClient

Source
pub struct RuntimeClient { /* private fields */ }
Expand description

Used by the Runtime to communicate with the internal endpoint.

Implementations§

Source§

impl<'ev> RuntimeClient

Source

pub fn new( host: &str, agent: Option<String>, runtime: Option<Runtime>, ) -> Result<Self, ApiError>

Creates a new instance of the Runtime APIclient SDK. The http client has timeouts disabled and will always send a Connection: keep-alive header. Optionally, the runtime client can receive a user agent string. This string is used to make requests to the runtime APIs and is used to identify the runtime being used by the function. For example, the lambda_runtime_core crate uses AWS_Lambda_Rust/0.1.0 (rustc/1.31.1-stable). The runtime client can also receive an instance of Tokio Runtime to use.

Source§

impl<'ev> RuntimeClient

Source

pub fn next_event(&self) -> Result<(Vec<u8>, EventContext), ApiError>

Polls for new events to the Runtime APIs.

Source

pub fn event_response( &self, request_id: &str, output: &[u8], ) -> Result<(), ApiError>

Calls the Lambda Runtime APIs to submit a response to an event. In this function we treat all errors from the API as an unrecoverable error. This is because the API returns 4xx errors for responses that are too long. In that case, we simply log the output and fail.

§Arguments
  • request_id The request id associated with the event we are serving the response for. This is returned as a header from the poll (/next) API.
  • output The object be sent back to the Runtime APIs as a response.
§Returns

A Result object containing a bool return value for the call or an error::ApiError instance.

Source

pub fn event_error( &self, request_id: &str, e: &ErrorResponse, ) -> Result<(), ApiError>

Calls Lambda’s Runtime APIs to send an error generated by the Handler. Because it’s rust, the error type for lambda is always handled.

§Arguments
  • request_id The request id associated with the event we are serving the error for.
  • e An instance of errors::HandlerError generated by the handler function.
§Returns

A Result object containing a bool return value for the call or an error::ApiError instance.

Source

pub fn fail_init(&self, e: &ErrorResponse)

Calls the Runtime APIs to report a failure during the init process. The contents of the error (e) parmeter are passed to the Runtime APIs using the private to_response() method.

§Arguments
  • e An instance of errors::RuntimeError.
§Panics

If it cannot send the init error. In this case we panic to force the runtime to restart.

Source

pub fn get_endpoint(&self) -> &str

Returns the endpoint configured for this HTTP Runtime client.

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, 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.