[−][src]Function cfn_resource_provider::process
pub fn process<F, R, P, S>(
f: F
) -> impl Fn(CfnRequest<P>) -> Box<dyn Future<Item = Option<S>, Error = Error> + Send> where
F: Fn(CfnRequest<P>) -> R + Send + Sync + 'static,
R: IntoFuture<Item = Option<S>, Error = Error> + Send + 'static,
R::Future: Send,
S: Serialize + Send + 'static,
P: PhysicalResourceIdSuffixProvider + Clone + Send + 'static,
Process an AWS CloudFormation custom resource request.
This function will, in conjunction with rust-aws-lambda
, deserialize the
JSON message sent by AWS CloudFormation into a strongly typed struct. Any custom resource
properties you might have can be specified to have them deserialized, too.
process
expects a single parameter, which should be a closure that receives a
CfnRequest<P>
as its only parameter, and is expected to return a type that can
succeed or fail (this can be a future or simply a Result
; anything that implements
IntoFuture
). The type returned for success has to be an Option<S>
, where S
needs to be
serializable. The failure type is expected to be failure::Error
. The computation required to
create your custom resource should happen in this closure.
The result of your closure will then be used to construct the response that will be sent to AWS
CloudFormation. This response informs AWS CloudFormation whether creating the custom resource
was successful or if it failed (including a reason for the failure). This is done by converting
the initial CfnRequest
into a CfnResponse
, pre-filling the
required fields based on the result your closure returned.
If your closure has errored, the failure reason will be extracted from the error you returned.
If your closure succeeded, the positive return value will be serialized into the
data
field (unless the returned Option
is None
). (Specifying
the [no_echo
option] is currently not possible.)
Example
extern crate aws_lambda as lambda; extern crate cfn_resource_provider as cfn; use cfn::*; fn main() { lambda::start(cfn::process(|event: CfnRequest<MyResourceProperties>| { // Perform the necessary steps to create the custom resource. Afterwards you can return // some data that should be serialized into the response. If you don't want to serialize // any data, you can return `None` (where you unfortunately have to specify the unknown // serializable type using the turbofish). Ok(None::<()>) })); }