MCPcopy Index your code
hub / github.com/aws/aws-lambda-rust-runtime / register

Method register

lambda-extension/src/extension.rs:246–351  ·  view source on GitHub ↗

Register the extension. Performs the [init phase](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-environment.html#runtimes-lifecycle-ib) Lambda lifecycle operations to register the extension. When implementing an internal Lambda extension, it is safe to call `lambda_runtime::run` once the future returned by this function resolves.

(self)

Source from the content-addressed store, hash-verified

244 /// extension, it is safe to call `lambda_runtime::run` once the future returned by this
245 /// function resolves.
246 pub async fn register(self) -> Result<RegisteredExtension<E>, Error> {
247 let client = &Client::builder().build()?;
248
249 let register_res = register(client, self.extension_name, self.events).await?;
250
251 // Logs API subscriptions must be requested during the Lambda init phase (see
252 // https://docs.aws.amazon.com/lambda/latest/dg/runtimes-logs-api.html#runtimes-logs-api-subscribing).
253 if let Some(mut log_processor) = self.logs_processor {
254 trace!("Log processor found");
255
256 validate_buffering_configuration(self.log_buffering)?;
257
258 let addr = SocketAddr::from(([0, 0, 0, 0], self.log_port_number));
259 let service = log_processor.make_service(());
260 let service = Arc::new(Mutex::new(service.await.unwrap()));
261 tokio::task::spawn(async move {
262 trace!("Creating new logs processor Service");
263
264 loop {
265 let service: Arc<Mutex<_>> = service.clone();
266 let make_service = service_fn(move |req: Request<Incoming>| log_wrapper(service.clone(), req));
267
268 let listener = TcpListener::bind(addr).await.unwrap();
269 let (tcp, _) = listener.accept().await.unwrap();
270 let io = TokioIo::new(tcp);
271 tokio::task::spawn(async move {
272 if let Err(err) = http1::Builder::new().serve_connection(io, make_service).await {
273 println!("Error serving connection: {err:?}");
274 }
275 });
276 }
277 });
278
279 trace!("Log processor started");
280
281 // Call Logs API to start receiving events
282 let req = requests::subscribe_request(
283 Api::LogsApi,
284 &register_res.extension_id,
285 self.log_types,
286 self.log_buffering,
287 self.log_port_number,
288 )?;
289 let res = client.call(req).await?;
290 if !res.status().is_success() {
291 let err = format!("unable to initialize the logs api: {}", res.status());
292 return Err(ExtensionError::boxed(err));
293 }
294 trace!("Registered extension with Logs API");
295 }
296
297 // Telemetry API subscriptions must be requested during the Lambda init phase (see
298 // https://docs.aws.amazon.com/lambda/latest/dg/telemetry-api.html#telemetry-api-registration
299 if let Some(mut telemetry_processor) = self.telemetry_processor {
300 trace!("Telemetry processor found");
301
302 validate_buffering_configuration(self.telemetry_buffering)?;
303

Callers 4

loadMethod · 0.80
runMethod · 0.80
mainFunction · 0.80

Calls 9

registerFunction · 0.85
log_wrapperFunction · 0.85
subscribe_requestFunction · 0.85
boxedFunction · 0.85
telemetry_wrapperFunction · 0.85
buildMethod · 0.80
cloneMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected