callLambda method

Future callLambda(
  1. String functionName,
  2. [dynamic parameters]
)

Parameters:

  • functionName is the name of the lambda that is to be called
  • parameters is a variable that either has to be of type Uint8List or Map depending on what the lambda function takes as an input parameter. If the lambd function takes no input parameter at all, just do not pass parameters.

Return:

  • If callLambda is called with a Uint8List as parameters value the lambda function is called with a byte array parameter and expected to return a byte array as well which will cause callLambda to return a Uint8List.
  • If callLambda is called with a Map as parameters value the lambda function is called with a json parameter and expected to return a json as well which will cause callLambda to return a Uint8List.

Implementation

Future<dynamic> callLambda(String functionName, [dynamic parameters]) async {
  Map<String, dynamic> preferences = {'identityPoolId': identityPoolId};
  ({
    'region': region,
    'cognitoRegion': cognitoRegion,
    'clientConfiguration': clientConfiguration
  }).forEach((key, value) {
    if (value != null) {
      preferences[key] = value;
    }
  });
  Map<String, dynamic> pass = {'preferences': preferences};
  if (parameters != null) {
    if (parameters is Map<String, dynamic> || parameters is Uint8List) {
      pass['parameters'] = parameters;
    } else {
      throw FormatException("Unsupported parameter type");
    }
  }
  dynamic ret = await platform.invokeMethod(functionName, pass);
  if (ret is Map && ret.runtimeType != Map) {
    ret = Map<String, dynamic>.from(ret);
  }
  return ret;
}