MCPcopy Index your code
hub / github.com/cargo-lambda/cargo-lambda / invoke_local

Method invoke_local

crates/cargo-lambda-invoke/src/lib.rs:217–270  ·  view source on GitHub ↗
(&self, data: &str)

Source from the content-addressed store, hash-verified

215 }
216
217 async fn invoke_local(&self, data: &str) -> Result<String> {
218 let host = parse_invoke_ip_address(&self.invoke_address)?;
219
220 let (protocol, client) = if self.tls_options.is_secure() {
221 let tls = self.tls_options.client_config()?;
222 let client = Client::builder()
223 .use_preconfigured_tls(tls)
224 .build()
225 .into_diagnostic()?;
226
227 ("https", client)
228 } else {
229 ("http", Client::new())
230 };
231
232 let url = format!(
233 "{}://{}:{}/2015-03-31/functions/{}/invocations",
234 protocol, &host, self.invoke_port, &self.function_name
235 );
236
237 let mut req = client.post(url).body(data.to_string());
238 if let Some(identity) = &self.cognito {
239 if identity.is_valid() {
240 let ser = serde_json::to_string(&identity)
241 .into_diagnostic()
242 .wrap_err("failed to serialize Cognito's identity information")?;
243 req = req.header(LAMBDA_RUNTIME_COGNITO_IDENTITY, ser);
244 }
245 }
246 if let Some(client_context) = self.client_context(false)? {
247 req = req.header(LAMBDA_RUNTIME_CLIENT_CONTEXT, client_context);
248 }
249
250 let resp = req
251 .send()
252 .await
253 .into_diagnostic()
254 .wrap_err("error sending request to the runtime emulator")?;
255 let success = resp.status() == StatusCode::OK;
256
257 let payload = resp
258 .text()
259 .await
260 .into_diagnostic()
261 .wrap_err("error reading response body")?;
262
263 if success {
264 Ok(payload)
265 } else {
266 debug!(error = ?payload, "error received from server");
267 let err = RemoteInvokeError::try_from(payload.as_str())?;
268 Err(err.into())
269 }
270 }
271
272 fn client_context(&self, encode: bool) -> Result<Option<String>> {
273 let mut data = if let Some(file) = &self.client_context_file {

Callers 1

runMethod · 0.80

Calls 8

parse_invoke_ip_addressFunction · 0.85
newFunction · 0.85
is_secureMethod · 0.80
client_configMethod · 0.80
buildMethod · 0.80
is_validMethod · 0.80
client_contextMethod · 0.80
as_strMethod · 0.80

Tested by

no test coverage detected