def _preprocess_records(self, processor: Dict, records: List[Record]) -> List[Dict]: """Preprocess the list of records by calling the given processor (e.g., Lamnda function).""" proc_type = processor.get("Type") parameters = processor.get("Parameters", []) parameters = { p["ParameterName"]: p["ParameterValue"] for p in parameters } if proc_type == "Lambda": lambda_arn = parameters.get("LambdaArn") # TODO: add support for other parameters, e.g., NumberOfRetries, BufferSizeInMBs, BufferIntervalInSeconds, ... client = aws_stack.connect_to_service("lambda") records = keys_to_lower(records) # Convert the record data to string (for json serialization) for record in records: if "data" in record: record["data"] = to_str(record["data"]) if "Data" in record: record["Data"] = to_str(record["Data"]) event = {"records": records} event = to_bytes(json.dumps(event)) response = client.invoke(FunctionName=lambda_arn, Payload=event) result = response.get("Payload").read() result = json.loads(to_str(result)) records = result.get("records", []) if result else [] else: LOG.warning("Unsupported Firehose processor type '%s'", proc_type) return records
def get_params(resource_props, stack_name, resources, resource_id): stage_name = resource_props.get("StageName", "default") resources[resource_id]["Properties"]["StageName"] = stage_name result = keys_to_lower(resource_props) param_names = [ "restApiId", "deploymentId", "description", "cacheClusterEnabled", "cacheClusterSize", "variables", "documentationVersion", "canarySettings", "tracingEnabled", "tags", ] result = select_attributes(result, param_names) result["tags"] = {t["key"]: t["value"] for t in result.get("tags", [])} result["stageName"] = stage_name return result
def get_params(params, **kwargs): result = keys_to_lower(params) param_names = [ "restApiId", "stageName", "deploymentId", "description", "cacheClusterEnabled", "cacheClusterSize", "variables", "documentationVersion", "canarySettings", "tracingEnabled", "tags", ] result = select_attributes(result, param_names) result["tags"] = { t["key"]: t["value"] for t in result.get("tags", []) } return result
def lambda_keys_to_lower(key=None): return lambda params, **kwargs: common.keys_to_lower(params.get(key) if key else params)