Skip to content

invoke_async async

invoke_async(
    function_name: NamespacedFunctionName,
    invoke_args: Body[AsyncIterator[bytes]] | AsyncIterator[bytes] | bytes,
    *,
    config_overrides: Optional[AsyncLambdaClientConfig] = None,
) -> InvokeAsyncResponse

For asynchronous function invocation, use Invoke.

Invokes a function asynchronously.

The payload limit is 256KB. For larger payloads, for up to 1MB, use Invoke.

If you do use the InvokeAsync action, note that it doesn't support the use of X-Ray active tracing. Trace ID is not propagated to the function, even if X-Ray active tracing is turned on.

Parameters:

  • function_name (NamespacedFunctionName) –

    The name or ARN of the Lambda function.

    Name formats

    • Function name – my-function.

    • Function ARN – arn:aws:lambda:us-west-2:123456789012:function:my-function.

    • Partial ARN – 123456789012:function:my-function.

    The length constraint applies only to the full ARN. If you specify only the function name, it is limited to 64 characters in length.

  • invoke_args (Body[AsyncIterator[bytes]] | AsyncIterator[bytes] | bytes) –

    The JSON that you want to provide to your Lambda function as input.

Raises:

  • EC2AccessDeniedException –

    Need additional permissions to configure VPC settings.

  • EC2ThrottledException –

    Amazon EC2 throttled Lambda during Lambda function initialization using the execution role provided for the function.

  • EC2UnexpectedException –

    Lambda received an unexpected Amazon EC2 client exception while setting up for the Lambda function.

  • EFSIOException –

    An error occurred when reading from or writing to a connected file system.

  • EFSMountConnectivityException –

    The Lambda function couldn't make a network connection to the configured file system.

  • EFSMountFailureException –

    The Lambda function couldn't mount the configured file system due to a permission or configuration issue.

  • EFSMountTimeoutException –

    The Lambda function made a network connection to the configured file system, but the mount operation timed out.

  • ENILimitReachedException –

    Lambda couldn't create an elastic network interface in the VPC, specified as part of Lambda function configuration, because the limit for network interfaces has been reached. For more information, see Lambda quotas.

  • InvalidRequestContentException –

    The request body could not be parsed as JSON, or a request header is invalid. For example, the 'x-amzn-RequestId' header is not a valid UUID string.

  • InvalidRuntimeException –

    The runtime or runtime version specified is not supported.

  • InvalidSecurityGroupIDException –

    The security group ID provided in the Lambda function VPC configuration is not valid.

  • InvalidSubnetIDException –

    The subnet ID provided in the Lambda function VPC configuration is not valid.

  • KMSAccessDeniedException –

    Lambda couldn't decrypt the environment variables because KMS access was denied. Check the Lambda function's KMS permissions.

  • KMSDisabledException –

    Lambda couldn't decrypt the environment variables because the KMS key used is disabled. Check the Lambda function's KMS key settings.

  • KMSInvalidStateException –

    Lambda couldn't decrypt the environment variables because the state of the KMS key used is not valid for Decrypt. Check the function's KMS key settings.

  • KMSNotFoundException –

    Lambda couldn't decrypt the environment variables because the KMS key was not found. Check the function's KMS key settings.

  • ModeNotSupportedException –

    The Lambda function doesn't support the invocation mode requested. For example, calling Invoke with InvocationType=RequestResponse on a function configured for asynchronous-only invocation, or vice versa. For more information about invocation types, see Invoking Lambda functions.

  • ResourceConflictException –

    The resource already exists, or another operation is in progress.

  • ResourceNotFoundException –

    The resource specified in the request does not exist.

  • S3FilesMountConnectivityException –

    The Lambda function couldn't make a network connection to the configured S3 Files access point.

  • S3FilesMountFailureException –

    The Lambda function couldn't mount the configured S3 Files access point due to a permission or configuration issue.

  • S3FilesMountTimeoutException –

    The Lambda function made a network connection to the configured S3 Files access point, but the mount operation timed out.

  • ServiceException –

    The Lambda service encountered an internal error.

  • ServiceQuotaExceededException –

    The request would exceed a service quota. For more information about Lambda service quotas, see Lambda quotas. To request a quota increase, see Requesting a quota increase in the Service Quotas User Guide.

  • SnapStartException –

    The afterRestore() runtime hook encountered an error. For more information, check the Amazon CloudWatch logs.

  • SnapStartNotReadyException –

    Lambda is initializing your function. You can invoke the function when the function state becomes Active.

  • SnapStartRegenerationFailureException –

    Lambda couldn't regenerate the SnapStart snapshot for the function. SnapStart-enabled functions periodically regenerate snapshots when their underlying runtime or dependencies change; this regeneration failed. Wait for Lambda to retry, or update the function's configuration to trigger a new snapshot. For more information, see Lambda SnapStart.

  • SnapStartTimeoutException –

    Lambda couldn't restore the snapshot within the timeout limit.

  • SubnetIPAddressLimitReachedException –

    Lambda couldn't set up VPC access for the Lambda function because one or more configured subnets has no available IP addresses.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

To invoke a Lambda function asynchronously The following example invokes a Lambda function asynchronously

>>> await client.invoke_async(function_name='my-function', invoke_args='{}')
Source code in docs_src/capo_lambda/_services/async__lambda.py
async def invoke_async(
    self,
    function_name: "capo_lambda.types.namespaced_function_name.NamespacedFunctionName",
    invoke_args: Body[AsyncIterator[bytes]] | AsyncIterator[bytes] | bytes,
    *,
    config_overrides: Optional[AsyncLambdaClientConfig] = None,
) -> "capo_lambda.types.invoke_async_response.InvokeAsyncResponse":
    """<note> <p>For asynchronous function invocation, use <a>Invoke</a>.</p> </note> <p>Invokes a function asynchronously.</p> <note> <p>The payload limit is 256KB. For larger payloads, for up to 1MB, use <a>Invoke</a>.</p> </note> <note> <p>If you do use the InvokeAsync action, note that it doesn't support the use of X-Ray active tracing. Trace ID is not propagated to the function, even if X-Ray active tracing is turned on.</p> </note>

    Args:
        function_name: <p>The name or ARN of the Lambda function.</p> <p class="title"> <b>Name formats</b> </p> <ul> <li> <p> <b>Function name</b> – <code>my-function</code>.</p> </li> <li> <p> <b>Function ARN</b> – <code>arn:aws:lambda:us-west-2:123456789012:function:my-function</code>.</p> </li> <li> <p> <b>Partial ARN</b> – <code>123456789012:function:my-function</code>.</p> </li> </ul> <p>The length constraint applies only to the full ARN. If you specify only the function name, it is limited to 64 characters in length.</p>
        invoke_args: <p>The JSON that you want to provide to your Lambda function as input.</p>

    Raises:
        capo_lambda.errors.ec2_access_denied_exception.EC2AccessDeniedException: <p>Need additional permissions to configure VPC settings.</p>
        capo_lambda.errors.ec2_throttled_exception.EC2ThrottledException: <p>Amazon EC2 throttled Lambda during Lambda function initialization using the execution role provided for the function.</p>
        capo_lambda.errors.ec2_unexpected_exception.EC2UnexpectedException: <p>Lambda received an unexpected Amazon EC2 client exception while setting up for the Lambda function.</p>
        capo_lambda.errors.efsio_exception.EFSIOException: <p>An error occurred when reading from or writing to a connected file system.</p>
        capo_lambda.errors.efs_mount_connectivity_exception.EFSMountConnectivityException: <p>The Lambda function couldn't make a network connection to the configured file system.</p>
        capo_lambda.errors.efs_mount_failure_exception.EFSMountFailureException: <p>The Lambda function couldn't mount the configured file system due to a permission or configuration issue.</p>
        capo_lambda.errors.efs_mount_timeout_exception.EFSMountTimeoutException: <p>The Lambda function made a network connection to the configured file system, but the mount operation timed out.</p>
        capo_lambda.errors.eni_limit_reached_exception.ENILimitReachedException: <p>Lambda couldn't create an elastic network interface in the VPC, specified as part of Lambda function configuration, because the limit for network interfaces has been reached. For more information, see <a href="https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html">Lambda quotas</a>.</p>
        capo_lambda.errors.invalid_request_content_exception.InvalidRequestContentException: <p>The request body could not be parsed as JSON, or a request header is invalid. For example, the 'x-amzn-RequestId' header is not a valid UUID string.</p>
        capo_lambda.errors.invalid_runtime_exception.InvalidRuntimeException: <p>The runtime or runtime version specified is not supported.</p>
        capo_lambda.errors.invalid_security_group_id_exception.InvalidSecurityGroupIDException: <p>The security group ID provided in the Lambda function VPC configuration is not valid.</p>
        capo_lambda.errors.invalid_subnet_id_exception.InvalidSubnetIDException: <p>The subnet ID provided in the Lambda function VPC configuration is not valid.</p>
        capo_lambda.errors.kms_access_denied_exception.KMSAccessDeniedException: <p>Lambda couldn't decrypt the environment variables because KMS access was denied. Check the Lambda function's KMS permissions.</p>
        capo_lambda.errors.kms_disabled_exception.KMSDisabledException: <p>Lambda couldn't decrypt the environment variables because the KMS key used is disabled. Check the Lambda function's KMS key settings.</p>
        capo_lambda.errors.kms_invalid_state_exception.KMSInvalidStateException: <p>Lambda couldn't decrypt the environment variables because the state of the KMS key used is not valid for Decrypt. Check the function's KMS key settings.</p>
        capo_lambda.errors.kms_not_found_exception.KMSNotFoundException: <p>Lambda couldn't decrypt the environment variables because the KMS key was not found. Check the function's KMS key settings.</p>
        capo_lambda.errors.mode_not_supported_exception.ModeNotSupportedException: <p>The Lambda function doesn't support the invocation mode requested. For example, calling <code>Invoke</code> with <code>InvocationType=RequestResponse</code> on a function configured for asynchronous-only invocation, or vice versa. For more information about invocation types, see <a href="https://docs.aws.amazon.com/lambda/latest/dg/invocation-options.html">Invoking Lambda functions</a>.</p>
        capo_lambda.errors.resource_conflict_exception.ResourceConflictException: <p>The resource already exists, or another operation is in progress.</p>
        capo_lambda.errors.resource_not_found_exception.ResourceNotFoundException: <p>The resource specified in the request does not exist.</p>
        capo_lambda.errors.s3_files_mount_connectivity_exception.S3FilesMountConnectivityException: <p>The Lambda function couldn't make a network connection to the configured S3 Files access point.</p>
        capo_lambda.errors.s3_files_mount_failure_exception.S3FilesMountFailureException: <p>The Lambda function couldn't mount the configured S3 Files access point due to a permission or configuration issue.</p>
        capo_lambda.errors.s3_files_mount_timeout_exception.S3FilesMountTimeoutException: <p>The Lambda function made a network connection to the configured S3 Files access point, but the mount operation timed out.</p>
        capo_lambda.errors.service_exception.ServiceException: <p>The Lambda service encountered an internal error.</p>
        capo_lambda.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The request would exceed a service quota. For more information about Lambda service quotas, see <a href="https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html">Lambda quotas</a>. To request a quota increase, see <a href="https://docs.aws.amazon.com/servicequotas/latest/userguide/request-quota-increase.html">Requesting a quota increase</a> in the <i>Service Quotas User Guide</i>.</p>
        capo_lambda.errors.snap_start_exception.SnapStartException: <p>The <code>afterRestore()</code> <a href="https://docs.aws.amazon.com/lambda/latest/dg/snapstart-runtime-hooks.html">runtime hook</a> encountered an error. For more information, check the Amazon CloudWatch logs.</p>
        capo_lambda.errors.snap_start_not_ready_exception.SnapStartNotReadyException: <p>Lambda is initializing your function. You can invoke the function when the <a href="https://docs.aws.amazon.com/lambda/latest/dg/functions-states.html">function state</a> becomes <code>Active</code>.</p>
        capo_lambda.errors.snap_start_regeneration_failure_exception.SnapStartRegenerationFailureException: <p>Lambda couldn't regenerate the SnapStart snapshot for the function. SnapStart-enabled functions periodically regenerate snapshots when their underlying runtime or dependencies change; this regeneration failed. Wait for Lambda to retry, or update the function's configuration to trigger a new snapshot. For more information, see <a href="https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html">Lambda SnapStart</a>.</p>
        capo_lambda.errors.snap_start_timeout_exception.SnapStartTimeoutException: <p>Lambda couldn't restore the snapshot within the timeout limit.</p>
        capo_lambda.errors.subnet_ip_address_limit_reached_exception.SubnetIPAddressLimitReachedException: <p>Lambda couldn't set up VPC access for the Lambda function because one or more configured subnets has no available IP addresses.</p>
        capo_lambda.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To invoke a Lambda function asynchronously
        The following example invokes a Lambda function asynchronously

        >>> await client.invoke_async(function_name='my-function', invoke_args='{}')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_lambda.types.invoke_async_request.InvokeAsyncRequest]",
    ) -> AsyncOperationResponse[
        "capo_lambda.types.invoke_async_response.InvokeAsyncResponse"
    ]:
        import capo_lambda._operations.aws_gir_api_service.invoke_async

        (
            output,
            http_response,
        ) = await capo_lambda._operations.aws_gir_api_service.invoke_async.async_invoke_async(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_lambda.types.invoke_async_request.InvokeAsyncRequest",
    ) -> dict[str, Any]:
        import capo_lambda.types.invoke_async_request

        return capo_lambda.types.invoke_async_request.redact_sensitive(input_)

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("InvokeAsync", redact_input=_redact_input),
    )
    input_: capo_lambda.types.invoke_async_request.InvokeAsyncRequest = {
        "function_name": function_name,
        "invoke_args": ensure_async_iterator(invoke_args),
    }

    async with aclosing_bodies(input_):
        response = await aexecute_pipeline(
            AsyncOperationRequest(input=input_, options=options_),
            handler=_handler,
            interceptors=list(interceptors_),
        )
        await response.response.aclose()
        return response.output