Mayfly.Context (Mayfly v1.0.0-rc.1)

Copy Markdown View Source

Per-invocation metadata, built from the GET /runtime/invocation/next response headers and passed as the second argument to Mayfly.Handler.handle/3.

FieldHeaderNotes
request_idLambda-Runtime-Aws-Request-Ididentifies the event; may be retried
invocation_idLambda-Runtime-Invocation-Ididentifies this attempt; echoed back by the runtime
deadline_msLambda-Runtime-Deadline-MsUnix time in ms
function_arnLambda-Runtime-Invoked-Function-Arn
trace_idLambda-Runtime-Trace-Idalso exported as _X_AMZN_TRACE_ID
tenant_idLambda-Runtime-Aws-Tenant-Idtenant isolation mode
client_contextLambda-Runtime-Client-ContextMobile SDK, raw JSON
cognito_identityLambda-Runtime-Cognito-IdentityMobile SDK, raw JSON

env carries the static function configuration read from the environment (AWS_LAMBDA_FUNCTION_NAME, ..._VERSION, ..._MEMORY_SIZE, AWS_REGION, AWS_LAMBDA_LOG_GROUP_NAME, AWS_LAMBDA_LOG_STREAM_NAME).

Summary

Functions

Reads the static function configuration from the environment.

Builds a context from lowercased response headers.

Logger metadata for this invocation.

Milliseconds until Lambda considers this invocation timed out (nil when unknown). On Lambda Managed Instances the runtime is not killed at the deadline, so check this in long loops and stop early.

Types

t()

@type t() :: %Mayfly.Context{
  client_context: String.t() | nil,
  cognito_identity: String.t() | nil,
  deadline_ms: non_neg_integer() | nil,
  env: %{optional(atom()) => String.t() | nil},
  function_arn: String.t() | nil,
  invocation_id: String.t() | nil,
  request_id: String.t() | nil,
  tenant_id: String.t() | nil,
  trace_id: String.t() | nil
}

Functions

env_from_system()

@spec env_from_system() :: map()

Reads the static function configuration from the environment.

from_headers(headers, env \\ %{})

@spec from_headers([{String.t(), String.t()}], map()) :: t()

Builds a context from lowercased response headers.

logger_metadata(ctx)

@spec logger_metadata(t()) :: keyword()

Logger metadata for this invocation.

remaining_time_ms(context)

@spec remaining_time_ms(t()) :: non_neg_integer() | nil

Milliseconds until Lambda considers this invocation timed out (nil when unknown). On Lambda Managed Instances the runtime is not killed at the deadline, so check this in long loops and stop early.