Lambda / Client / invoke_with_response_stream

invoke_with_response_stream#

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.

See also: AWS API Documentation

Request Syntax

response = client.invoke_with_response_stream(
    FunctionName='string',
    InvocationType='RequestResponse'|'DryRun',
    LogType='None'|'Tail',
    ClientContext='string',
    Qualifier='string',
    Payload=b'bytes'|file
)
Parameters:
  • FunctionName (string) –

    [REQUIRED]

    The name of the Lambda function.

    Name formats

    • Function namemy-function.

    • Function ARNarn:aws:lambda:us-west-2:123456789012:function:my-function.

    • Partial ARN123456789012: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.

  • InvocationType (string) –

    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.

  • LogType (string) – Set to Tail to include the execution log in the response. Applies to synchronously invoked functions only.

  • ClientContext (string) – Up to 3,583 bytes of base64-encoded data about the invoking client to pass to the function in the context object.

  • Qualifier (string) – The alias name.

  • Payload (bytes or seekable file-like object) –

    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.

Return type:

dict

Returns:

The response of this operation contains an EventStream member. When iterated the 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 (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

  • Lambda.Client.exceptions.ServiceException

  • Lambda.Client.exceptions.ResourceNotFoundException

  • Lambda.Client.exceptions.InvalidRequestContentException

  • Lambda.Client.exceptions.RequestTooLargeException

  • Lambda.Client.exceptions.UnsupportedMediaTypeException

  • Lambda.Client.exceptions.TooManyRequestsException

  • Lambda.Client.exceptions.InvalidParameterValueException

  • Lambda.Client.exceptions.EC2UnexpectedException

  • Lambda.Client.exceptions.SubnetIPAddressLimitReachedException

  • Lambda.Client.exceptions.ENILimitReachedException

  • Lambda.Client.exceptions.EFSMountConnectivityException

  • Lambda.Client.exceptions.EFSMountFailureException

  • Lambda.Client.exceptions.EFSMountTimeoutException

  • Lambda.Client.exceptions.EFSIOException

  • Lambda.Client.exceptions.EC2ThrottledException

  • Lambda.Client.exceptions.EC2AccessDeniedException

  • Lambda.Client.exceptions.InvalidSubnetIDException

  • Lambda.Client.exceptions.InvalidSecurityGroupIDException

  • Lambda.Client.exceptions.InvalidZipFileException

  • Lambda.Client.exceptions.KMSDisabledException

  • Lambda.Client.exceptions.KMSInvalidStateException

  • Lambda.Client.exceptions.KMSAccessDeniedException

  • Lambda.Client.exceptions.KMSNotFoundException

  • Lambda.Client.exceptions.InvalidRuntimeException

  • Lambda.Client.exceptions.ResourceConflictException

  • Lambda.Client.exceptions.ResourceNotReadyException