def update_cache_behavior()

in source/cfn-add-edge-lambda/cfn-add-edge-lambda.py [0:0]


def update_cache_behavior(behavior, lambda_association):
    # only proceed if this is not a smooth streaming behavior
    if not behavior.get("SmoothStreaming", False):
        # default to an empty list if none yet
        behavior["LambdaFunctionAssociations"]["Items"] = behavior[
            "LambdaFunctionAssociations"].get("Items", [])
        # look for existing associations
        matches = [
            x for x in behavior["LambdaFunctionAssociations"]["Items"]
            if x["EventType"] == lambda_association["EventType"]
        ]
        if len(matches) > 0:
            # replace the lambda arn with the new lambda
            matches[0]["LambdaFunctionARN"] = lambda_association[
                "LambdaFunctionARN"]
            matches[0]["IncludeBody"] = lambda_association["IncludeBody"]
        else:
            # create a new association
            behavior["LambdaFunctionAssociations"]["Items"].append(
                lambda_association)
            behavior["LambdaFunctionAssociations"]["Quantity"] = behavior[
                "LambdaFunctionAssociations"]["Quantity"] + 1