def gen_model(model_name, image_tag, timeout, num_of_workers):
    """
    Generates the Sagemaker model that will be loaded to the endpoint instances.
    """

    model = {
        "SagemakerModel": {
            "Type": "AWS::SageMaker::Model",
            "Properties": {
                "ModelName": model_name,
                "ExecutionRoleArn": {"Fn::GetAtt": ["ExecutionRole", "Arn"]},
                "PrimaryContainer": {
                    "Image": image_tag,
                    "ImageConfig": {"RepositoryAccessMode": "Platform"},
                    "Environment": {
                        "BENTOML_GUNICORN_TIMEOUT": timeout,
                        "BENTOML_GUNICORN_NUM_OF_WORKERS": num_of_workers,
                    },
                },
            },
        },
        "ExecutionRole": {
            "Type": "AWS::IAM::Role",
            "Properties": {
                "ManagedPolicyArns": [
                    "arn:aws:iam::aws:policy/AmazonSageMakerFullAccess"
                ],
                "AssumeRolePolicyDocument": {
                    "Version": "2012-10-17",
                    "Statement": [
                        {
                            "Effect": "Allow",
                            "Principal": {"Service": ["sagemaker.amazonaws.com"]},
                            "Action": ["sts:AssumeRole"],
                        }
                    ],
                },
            },
        },
    }

    return model