invoke¶
Operation¶
invoke
async
¶
invoke(input: InvokeInput, plugins: list[Plugin] | None = None) -> InvokeOutput
Invokes a Lambda function. You can invoke a function synchronously (and
wait for the response), or asynchronously. By default, Lambda invokes
your function synchronously (i.e. theInvocationType is
RequestResponse). To invoke a function asynchronously, set
InvocationType to Event. Lambda passes the ClientContext object to
your function for synchronous invocations only.
For synchronous invocations, the maximum payload size is 6 MB. For asynchronous invocations, the maximum payload size is 1 MB.
For synchronous invocation, details about the function response, including errors, are included in the response body and headers. For either invocation type, you can find more information in the execution log and trace.
When an error occurs, your function may be invoked multiple times. Retry behavior varies by error type, client, event source, and invocation type. For example, if you invoke a function asynchronously and it returns an error, Lambda executes the function up to two more times. For more information, see Error handling and automatic retries in Lambda.
For asynchronous invocation, Lambda adds events to a queue before sending them to your function. If your function does not have enough capacity to keep up with the queue, events may be lost. Occasionally, your function may receive the same event multiple times, even if no error occurs. To retain events that were not processed, configure your function with a dead-letter queue.
The status code in the API response doesn't reflect function errors.
Error codes are reserved for errors that prevent your function from
executing, such as permissions errors,
quota
errors, or issues with your function's code and configuration. For
example, Lambda returns TooManyRequestsException if running the
function would cause you to exceed a concurrency limit at either the
account level (ConcurrentInvocationLimitExceeded) or function level
(ReservedFunctionConcurrentInvocationLimitExceeded).
For functions with a long timeout, your client might disconnect during synchronous invocation while it waits for a response. Configure your HTTP client, SDK, firewall, proxy, or operating system to allow for long connections with timeout or keep-alive settings.
This operation requires permission for the lambda:InvokeFunction action. For details on how to set up permissions for cross-account invocations, see Granting function access to other accounts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
InvokeInput
|
An instance of |
required |
plugins
|
list[Plugin] | None
|
A list of callables that modify the configuration dynamically. Changes made by these plugins only apply for the duration of the operation execution and will not affect any other operation invocations. |
None
|
Returns:
| Type | Description |
|---|---|
InvokeOutput
|
An instance of |
Input¶
InvokeInput
dataclass
¶
Dataclass for InvokeInput structure.
Attributes¶
client_context
class-attribute
instance-attribute
¶
client_context: str | None = None
Up to 3,583 bytes of base64-encoded data about the invoking client to
pass to the function in the context object. Lambda passes the
ClientContext object to your function for synchronous invocations
only.
durable_execution_name
class-attribute
instance-attribute
¶
durable_execution_name: str | None = None
A unique name for the durable execution. If you invoke a durable
function using a name that already exists with the same payload, Lambda
returns the existing execution instead of creating a duplicate. If the
payload differs, Lambda returns a
DurableExecutionAlreadyStartedException error.
If not specified, Lambda generates a unique identifier automatically. For more information, see Execution names.
function_name
class-attribute
instance-attribute
¶
function_name: str | None = None
The name or ARN of the Lambda function, version, or alias.
Name formats
-
Function name --
my-function(name-only),my-function:v1(with alias). -
Function ARN --
arn:aws:lambda:us-west-2:123456789012:function:my-function. -
Partial ARN --
123456789012:function:my-function.
You can append a version number or alias to any of the formats. The length constraint applies only to the full ARN. If you specify only the function name, it is limited to 64 characters in length.
invocation_type
class-attribute
instance-attribute
¶
invocation_type: InvocationType | None = None
Choose from the following options.
-
RequestResponse(default) -- Invoke the function synchronously. Keep the connection open until the function returns a response or times out. The API response includes the function response and additional data. -
Event-- Invoke the function asynchronously. Send events that fail multiple times to the function's dead-letter queue (if one is configured). The API response only includes a status code. -
DryRun-- Validate parameter values and verify that the user or role has permission to invoke the function.
log_type
class-attribute
instance-attribute
¶
log_type: LogType | None = None
Set to Tail to include the execution log in the response. Applies to
synchronously invoked functions only.
payload
class-attribute
instance-attribute
¶
The JSON that you want to provide to your Lambda function as input. The maximum payload size is 6 MB for synchronous invocations and 1 MB for asynchronous invocations.
You can enter the JSON directly. For example,
--payload '{ "key": "value" }'. You can also specify a file path. For
example, --payload file://payload.json.
Output¶
InvokeOutput
dataclass
¶
Dataclass for InvokeOutput structure.
Attributes¶
durable_execution_arn
class-attribute
instance-attribute
¶
durable_execution_arn: str | None = None
The ARN of the durable execution that was started. This is returned when invoking a durable function and provides a unique identifier for tracking the execution.
executed_version
class-attribute
instance-attribute
¶
executed_version: str | None = None
The version of the function that executed. When you invoke a function with an alias, this indicates which version the alias resolved to.
function_error
class-attribute
instance-attribute
¶
function_error: str | None = None
If present, indicates that an error occurred during function execution. Details about the error are included in the response payload.
log_result
class-attribute
instance-attribute
¶
log_result: str | None = None
The last 4 KB of the execution log, which is base64-encoded.
payload
class-attribute
instance-attribute
¶
The response from the function, or an error object.
status_code
class-attribute
instance-attribute
¶
status_code: int = 0
The HTTP status code is in the 200 range for a successful request. For
the RequestResponse invocation type, this status code is 200. For the
Event invocation type, this status code is 202. For the DryRun
invocation type, the status code is 204.