:doc:`Lambda <../../lambda>` / Client / invoke_with_response_stream

***************************
invoke_with_response_stream
***************************



.. py:method:: Lambda.Client.invoke_with_response_stream(**kwargs)

  

  Configure your Lambda functions to stream response payloads back to clients. For more information, see `Configuring a Lambda function to stream responses <https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html>`__.

   

  This operation requires permission for the `lambda\:InvokeFunction <https://docs.aws.amazon.com/IAM/latest/UserGuide/list_awslambda.html>`__ action. For details on how to set up permissions for cross-account invocations, see `Granting function access to other accounts <https://docs.aws.amazon.com/lambda/latest/dg/access-control-resource-based.html#permissions-resource-xaccountinvoke>`__.

  

  See also: `AWS API Documentation <https://docs.aws.amazon.com/goto/WebAPI/lambda-2015-03-31/InvokeWithResponseStream>`_  


  **Request Syntax**
  ::

    response = client.invoke_with_response_stream(
        FunctionName='string',
        InvocationType='RequestResponse'|'DryRun',
        LogType='None'|'Tail',
        ClientContext='string',
        Qualifier='string',
        Payload=b'bytes'|file,
        TenantId='string'
    )
    
  :type FunctionName: string
  :param FunctionName: **[REQUIRED]** 

    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.

    

  
  :type InvocationType: string
  :param InvocationType: 

    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.
    

    

  
  :type LogType: string
  :param LogType: 

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

    

  
  :type ClientContext: string
  :param ClientContext: 

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

    

  
  :type Qualifier: string
  :param Qualifier: 

    The alias name.

    

  
  :type Payload: bytes or seekable file-like object
  :param Payload: 

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

    

  
  :type TenantId: string
  :param TenantId: 

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

    

  
  
  :rtype: dict
  :returns: 
    

    The response of this operation contains an :class:`.EventStream` member. When iterated the :class:`.EventStream` will yield events based on the structure below, where only one of the top level keys will be present for any given event.
    
    **Response Syntax**

    
    ::

      {
          'StatusCode': 123,
          'ExecutedVersion': 'string',
          'EventStream': EventStream({
              'PayloadChunk': {
                  'Payload': b'bytes'
              },
              'InvokeComplete': {
                  'ErrorCode': 'string',
                  'ErrorDetails': 'string',
                  'LogResult': 'string'
              }
          }),
          'ResponseStreamContentType': 'string'
      }
      
    **Response Structure**

    

    - *(dict) --* 
      

      - **StatusCode** *(integer) --* 

        For a successful request, the HTTP status code is in the 200 range. For the ``RequestResponse`` invocation type, this status code is 200. For the ``DryRun`` invocation type, this status code is 204.

        
      

      - **ExecutedVersion** *(string) --* 

        The version of the function that executed. When you invoke a function with an alias, this indicates which version the alias resolved to.

        
      

      - **EventStream** (:class:`.EventStream`) -- 

        The stream of response payloads.

        
        

        - **PayloadChunk** *(dict) --* 

          A chunk of the streamed response payload.

          
          

          - **Payload** *(bytes) --* 

            Data returned by your Lambda function.

            
      
        

        - **InvokeComplete** *(dict) --* 

          An object that's returned when the stream has ended and all the payload chunks have been returned.

          
          

          - **ErrorCode** *(string) --* 

            An error code.

            
          

          - **ErrorDetails** *(string) --* 

            The details of any returned error.

            
          

          - **LogResult** *(string) --* 

            The last 4 KB of the execution log, which is base64-encoded.

            
      
    
      

      - **ResponseStreamContentType** *(string) --* 

        The type of data the stream is returning.

        
  
  **Exceptions**
  
  *   :py:class:`Lambda.Client.exceptions.ResourceNotReadyException`

  
  *   :py:class:`Lambda.Client.exceptions.InvalidSecurityGroupIDException`

  
  *   :py:class:`Lambda.Client.exceptions.SnapStartTimeoutException`

  
  *   :py:class:`Lambda.Client.exceptions.TooManyRequestsException`

  
  *   :py:class:`Lambda.Client.exceptions.EC2ThrottledException`

  
  *   :py:class:`Lambda.Client.exceptions.EFSMountConnectivityException`

  
  *   :py:class:`Lambda.Client.exceptions.SubnetIPAddressLimitReachedException`

  
  *   :py:class:`Lambda.Client.exceptions.KMSAccessDeniedException`

  
  *   :py:class:`Lambda.Client.exceptions.RequestTooLargeException`

  
  *   :py:class:`Lambda.Client.exceptions.KMSDisabledException`

  
  *   :py:class:`Lambda.Client.exceptions.UnsupportedMediaTypeException`

  
  *   :py:class:`Lambda.Client.exceptions.SerializedRequestEntityTooLargeException`

  
  *   :py:class:`Lambda.Client.exceptions.InvalidRuntimeException`

  
  *   :py:class:`Lambda.Client.exceptions.NoPublishedVersionException`

  
  *   :py:class:`Lambda.Client.exceptions.EC2UnexpectedException`

  
  *   :py:class:`Lambda.Client.exceptions.InvalidSubnetIDException`

  
  *   :py:class:`Lambda.Client.exceptions.KMSNotFoundException`

  
  *   :py:class:`Lambda.Client.exceptions.InvalidParameterValueException`

  
  *   :py:class:`Lambda.Client.exceptions.EC2AccessDeniedException`

  
  *   :py:class:`Lambda.Client.exceptions.EFSIOException`

  
  *   :py:class:`Lambda.Client.exceptions.KMSInvalidStateException`

  
  *   :py:class:`Lambda.Client.exceptions.ResourceConflictException`

  
  *   :py:class:`Lambda.Client.exceptions.ENILimitReachedException`

  
  *   :py:class:`Lambda.Client.exceptions.SnapStartNotReadyException`

  
  *   :py:class:`Lambda.Client.exceptions.ServiceException`

  
  *   :py:class:`Lambda.Client.exceptions.SnapStartException`

  
  *   :py:class:`Lambda.Client.exceptions.RecursiveInvocationException`

  
  *   :py:class:`Lambda.Client.exceptions.EFSMountTimeoutException`

  
  *   :py:class:`Lambda.Client.exceptions.ResourceNotFoundException`

  
  *   :py:class:`Lambda.Client.exceptions.InvalidRequestContentException`

  
  *   :py:class:`Lambda.Client.exceptions.InvalidZipFileException`

  
  *   :py:class:`Lambda.Client.exceptions.EFSMountFailureException`

  