Using the Lambda context object to retrieve Rust function information
Note
The Rust runtime client
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 AWS 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 AWS X-Ray trace ID for the current invocation. -
client_content
: The client context object sent by the AWS mobile SDK. This field is empty unless the function is invoked using an AWS 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 AWS 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 }