invokeWithResponseStream method

Future<InvokeWithResponseStreamResponse> invokeWithResponseStream({
  1. required String functionName,
  2. String? clientContext,
  3. ResponseStreamingInvocationType? invocationType,
  4. LogType? logType,
  5. Uint8List? payload,
  6. String? qualifier,
  7. String? tenantId,
})

Configure your Lambda 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.

May throw EC2AccessDeniedException. May throw EC2ThrottledException. May throw EC2UnexpectedException. May throw EFSIOException. May throw EFSMountConnectivityException. May throw EFSMountFailureException. May throw EFSMountTimeoutException. May throw ENILimitReachedException. May throw InvalidParameterValueException. May throw InvalidRequestContentException. May throw InvalidRuntimeException. May throw InvalidSecurityGroupIDException. May throw InvalidSubnetIDException. May throw InvalidZipFileException. May throw KMSAccessDeniedException. May throw KMSDisabledException. May throw KMSInvalidStateException. May throw KMSNotFoundException. May throw NoPublishedVersionException. May throw RecursiveInvocationException. May throw RequestTooLargeException. May throw ResourceConflictException. May throw ResourceNotFoundException. May throw ResourceNotReadyException. May throw S3FilesMountConnectivityException. May throw S3FilesMountFailureException. May throw S3FilesMountTimeoutException. May throw SerializedRequestEntityTooLargeException. May throw ServiceException. May throw SnapStartException. May throw SnapStartNotReadyException. May throw SnapStartTimeoutException. May throw SubnetIPAddressLimitReachedException. May throw TooManyRequestsException. May throw UnsupportedMediaTypeException.

Parameter functionName : The name or ARN 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.

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

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

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

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

Parameter qualifier : The alias name.

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

Implementation

Future<InvokeWithResponseStreamResponse> invokeWithResponseStream({
  required String functionName,
  String? clientContext,
  ResponseStreamingInvocationType? invocationType,
  LogType? logType,
  Uint8List? payload,
  String? qualifier,
  String? tenantId,
}) async {
  final headers = <String, String>{
    if (clientContext != null)
      'X-Amz-Client-Context': clientContext.toString(),
    if (invocationType != null) 'X-Amz-Invocation-Type': invocationType.value,
    if (logType != null) 'X-Amz-Log-Type': logType.value,
    if (tenantId != null) 'X-Amz-Tenant-Id': tenantId.toString(),
  };
  final $query = <String, List<String>>{
    if (qualifier != null) 'Qualifier': [qualifier],
  };
  final response = await _protocol.sendRaw(
    payload: payload,
    method: 'POST',
    requestUri:
        '/2021-11-15/functions/${Uri.encodeComponent(functionName)}/response-streaming-invocations',
    queryParams: $query,
    headers: headers,
    exceptionFnMap: _exceptionFns,
  );
  final $json = await _s.jsonFromResponse(response);
  return InvokeWithResponseStreamResponse(
    eventStream: InvokeWithResponseStreamResponseEvent.fromJson($json),
    executedVersion: _s.extractHeaderStringValue(
        response.headers, 'X-Amz-Executed-Version'),
    responseStreamContentType:
        _s.extractHeaderStringValue(response.headers, 'Content-Type'),
    statusCode: response.statusCode,
  );
}