Skip to content

invoke_with_response_stream async

invoke_with_response_stream(
    function_name: NamespacedFunctionName,
    *,
    config_overrides: Optional[AsyncLambdaClientConfig] = None,
    log_type: Optional[LogType] = None,
    client_context: Optional[String] = None,
    qualifier: Optional[NumericLatestPublishedOrAliasQualifier] = None,
    payload: Optional[Blob] = None,
    tenant_id: Optional[TenantId] = None,
    invocation_type: Optional[ResponseStreamingInvocationType] = None,
) -> AsyncGenerator[InvokeWithResponseStreamResponse]

Configure your Lambda Event Functions to stream response payloads back to clients. For more information, see Configuring a Lambda function to stream responses.

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:

  • 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.

  • log_type (Optional[LogType], default: None ) –

    Set to Tail to include the execution log in the response. Applies to synchronously invoked functions only.

  • client_context (Optional[String], default: None ) –

    Up to 3,583 bytes of base64-encoded data about the invoking client to pass to the function in the context object.

  • qualifier (Optional[NumericLatestPublishedOrAliasQualifier], default: None ) –

    The alias name.

  • payload (Optional[Blob], default: None ) –

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

    You can enter the JSON directly. For example, --payload '{ "key": "value" }'. You can also specify a file path. For example, --payload file://payload.json.

  • tenant_id (Optional[TenantId], default: None ) –

    The identifier of the tenant in a multi-tenant Lambda function.

  • invocation_type (Optional[ResponseStreamingInvocationType], default: None ) –

    Use one of the following options:

    • RequestResponse (default) – Invoke the function synchronously. Keep the connection open until the function returns a response or times out. The API operation response includes the function response and additional data.

    • DryRun – Validate parameter values and verify that the IAM user or role has permission to invoke the function.

Raises:

Source code in docs_src/capo_lambda/_services/async__lambda.py
@asynccontextmanager
async def invoke_with_response_stream(
    self,
    function_name: "capo_lambda.types.namespaced_function_name.NamespacedFunctionName",
    *,
    config_overrides: Optional[AsyncLambdaClientConfig] = None,
    log_type: Optional["capo_lambda.types.log_type.LogType"] = None,
    client_context: Optional["capo_lambda.types.string.String"] = None,
    qualifier: Optional[
        "capo_lambda.types.numeric_latest_published_or_alias_qualifier.NumericLatestPublishedOrAliasQualifier"
    ] = None,
    payload: Optional["capo_lambda.types.blob.Blob"] = None,
    tenant_id: Optional["capo_lambda.types.tenant_id.TenantId"] = None,
    invocation_type: Optional[
        "capo_lambda.types.response_streaming_invocation_type.ResponseStreamingInvocationType"
    ] = None,
) -> "AsyncGenerator[capo_lambda.types.invoke_with_response_stream_response.InvokeWithResponseStreamResponse]":
    """<p>Configure your Lambda Event Functions to stream response payloads back to clients. For more information, see <a href="https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html">Configuring a Lambda function to stream responses</a>.</p> <p>This operation requires permission for the <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/list_awslambda.html">lambda:InvokeFunction</a> action. For details on how to set up permissions for cross-account invocations, see <a href="https://docs.aws.amazon.com/lambda/latest/dg/access-control-resource-based.html#permissions-resource-xaccountinvoke">Granting function access to other accounts</a>.</p>

    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>
        log_type: <p>Set to <code>Tail</code> to include the execution log in the response. Applies to synchronously invoked functions only.</p>
        client_context: <p>Up to 3,583 bytes of base64-encoded data about the invoking client to pass to the function in the context object.</p>
        qualifier: <p>The alias name.</p>
        payload: <p>The JSON that you want to provide to your Lambda function as input.</p> <p>You can enter the JSON directly. For example, <code>--payload '{ "key": "value" }'</code>. You can also specify a file path. For example, <code>--payload file://payload.json</code>.</p>
        tenant_id: <p>The identifier of the tenant in a multi-tenant Lambda function.</p>
        invocation_type: <p>Use one of the following options:</p> <ul> <li> <p> <code>RequestResponse</code> (default) – Invoke the function synchronously. Keep the connection open until the function returns a response or times out. The API operation response includes the function response and additional data.</p> </li> <li> <p> <code>DryRun</code> – Validate parameter values and verify that the IAM user or role has permission to invoke the function.</p> </li> </ul>

    Raises:
        capo_lambda.errors.code_artifact_user_deleted_exception.CodeArtifactUserDeletedException: <p>The Lambda function couldn't be invoked because its code artifact user has been deleted. Wait for Lambda to provision a new code artifact user, or update the function's code package to recreate it.</p>
        capo_lambda.errors.code_artifact_user_failed_exception.CodeArtifactUserFailedException: <p>The Lambda function couldn't be invoked because provisioning of its code artifact user failed. Update the function's code package or check the Lambda function's <code>State</code> and <code>StateReasonCode</code> for additional context.</p>
        capo_lambda.errors.code_artifact_user_pending_exception.CodeArtifactUserPendingException: <p>The Lambda function couldn't be invoked because its code artifact user is still being provisioned. Wait for the function's <code>State</code> to become <code>Active</code> and try the request again.</p>
        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_parameter_value_exception.InvalidParameterValueException: <p>One of the parameters in the request is not valid.</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.invalid_zip_file_exception.InvalidZipFileException: <p>Lambda could not unzip the deployment package.</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.no_published_version_exception.NoPublishedVersionException: <p>The function has no published versions available.</p>
        capo_lambda.errors.recursive_invocation_exception.RecursiveInvocationException: <p>Lambda has detected your function being invoked in a recursive loop with other Amazon Web Services resources and stopped your function's invocation.</p>
        capo_lambda.errors.request_too_large_exception.RequestTooLargeException: <p>The request payload exceeded the <code>Invoke</code> request body JSON input quota. For more information, see <a href="https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html">Lambda quotas</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.resource_not_ready_exception.ResourceNotReadyException: <p>The function is inactive and its VPC connection is no longer available. Wait for the VPC connection to reestablish and try again.</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.serialized_request_entity_too_large_exception.SerializedRequestEntityTooLargeException: <p>The request payload exceeded the maximum allowed size for serialized request entities.</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.too_many_requests_exception.TooManyRequestsException: <p>The request throughput limit was exceeded. For more information, see <a href="https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html#api-requests">Lambda quotas</a>.</p>
        capo_lambda.errors.unsupported_media_type_exception.UnsupportedMediaTypeException: <p>The content type of the <code>Invoke</code> request body is not JSON.</p>
        capo_lambda.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_lambda.types.invoke_with_response_stream_request.InvokeWithResponseStreamRequest]",
    ) -> AsyncOperationResponse[
        "capo_lambda.types.invoke_with_response_stream_response.InvokeWithResponseStreamResponse"
    ]:
        import capo_lambda._operations.aws_gir_api_service.invoke_with_response_stream

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

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

        return (
            capo_lambda.types.invoke_with_response_stream_request.redact_sensitive(
                input_
            )
        )

    def _redact_output(
        output: "capo_lambda.types.invoke_with_response_stream_response.InvokeWithResponseStreamResponse",
    ) -> dict[str, Any]:
        import capo_lambda.types.invoke_with_response_stream_response

        return (
            capo_lambda.types.invoke_with_response_stream_response.redact_sensitive(
                output
            )
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "InvokeWithResponseStream",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_lambda.types.invoke_with_response_stream_request.InvokeWithResponseStreamRequest = {
        "function_name": function_name
    }
    if log_type is not None:
        input_["log_type"] = log_type
    if client_context is not None:
        input_["client_context"] = client_context
    if qualifier is not None:
        input_["qualifier"] = qualifier
    if payload is not None:
        input_["payload"] = payload
    if tenant_id is not None:
        input_["tenant_id"] = tenant_id
    if invocation_type is not None:
        input_["invocation_type"] = invocation_type

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    try:
        yield response.output
    finally:
        await response.response.aclose()