Lambda context object in Rust - Amazon Lambda
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Lambda context object in Rust

Note

The Rust runtime client is an experimental package. It is subject to change and intended only for evaluation purposes.

When Lambda runs your function, it adds a context object to the LambdaEvent that the handler receives. This object provides properties with information about the invocation, function, and execution environment.

Context properties
  • request_id: The Amazon request ID generated by the Lambda service.

  • deadline: The execution deadline for the current invocation in milliseconds.

  • invoked_function_arn: The Amazon Resource Name (ARN) of the Lambda function being invoked.

  • xray_trace_id: The Amazon X-Ray trace ID for the current invocation.

  • client_content: The client context object sent by the Amazon mobile SDK. This field is empty unless the function is invoked using an Amazon mobile SDK.

  • identity: The Amazon Cognito identity that invoked the function. This field is empty unless the invocation request to the Lambda APIs was made using Amazon credentials issued by Amazon Cognito identity pools.

  • env_config: The Lambda function configuration from the local environment variables. This property includes information such as the function name, memory allocation, version, and log streams.

Accessing invoke context information

Lambda functions have access to metadata about their environment and the invocation request. The LambaEvent object that your function handler receives includes the context metadata:

use lambda_runtime::{service_fn, LambdaEvent, Error}; use serde_json::{json, Value}; async fn handler(event: LambdaEvent<Value>) -> Result<Value, Error> { let invoked_function_arn = event.context.invoked_function_arn; Ok(json!({ "message": format!("Hello, this is function {invoked_function_arn}!") })) } #[tokio::main] async fn main() -> Result<(), Error> { lambda_runtime::run(service_fn(handler)).await }