{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "How service providers can use natural language processing to gain insights from customer free-text requests",
    "Parameters": {
        "OperationScoreThreshold": {
            "Default": 0.5,
            "Type": "Number",
            "MinValue": 0,
            "MaxValue": 1,
            "Description": "Threshold for operation classification score. If the classification score is below than this, the recommendation will not be provided as the classification may be incorrect."
        },
        "ResourceScoreThreshold": {
            "Default": 0.5,
            "Type": "Number",
            "MinValue": 0,
            "MaxValue": 1,
            "Description": "Threshold for resource classification score. If the classification score is below than this, the recommendation will not be provided as the classification may be incorrect."
        },
        "ComprehendTicketOperationClassifierEndpoint": {
            "Default": "ticket-classification-operation",
            "Type": "String",
            "AllowedPattern": "^[a-zA-Z0-9](-*[a-zA-Z0-9]){1,64}$",
            "Description": "The endpoint name of Amazon Comprehend ticket operation classifier."
        },
        "ComprehendTicketResourceClassifierEndpoint": {
            "Default": "ticket-classification-resource",
            "Type": "String",
            "AllowedPattern": "^[a-zA-Z0-9](-*[a-zA-Z0-9]){1,64}$",
            "Description": "The endpoint name of Amazon Comprehend ticket resource classifier."
        },
        "ClassificationDeliveryStreamName": {
            "Default": "ticketclassification",
            "Type": "String",
            "AllowedPattern": "^[a-zA-Z0-9_.-]{1,64}$",
            "Description": "The name of Amazon Kinesis Data Firehose delivery steam. Kinesis Data Firehose is used to push the classification data into Amazon Redshift cluster."
        },
        "ClassificationRedshiftClusterUsername": {
            "Type": "String",
            "AllowedPattern": "^([a-z])([a-z]|[0-9]){0,127}$",
            "Description": "The user name associated with the admin user account for Amazon Redshift cluster."
        },
        "ClassificationRedshiftClusterPasswordSecretName": {
            "Default": "ClassificationRedshiftClusterPassword",
            "Type": "String",
            "AllowedPattern": "^[a-zA-Z0-9/_+=.@-]{1,128}$",
            "Description": "Secret name of AWS Secrets Manager which store Redshift Cluster Password."
        },
        "ClassificationRedshiftClusterDBName": {
            "Default": "ticketclassification",
            "Type": "String",
            "AllowedPattern": "^[a-z0-9]{1,64}$",
            "Description": "The name of the first database to be created when Amazon Redshift cluster is created. In this walk-through, we will use the first database."
        },
        "ClassificationRedshiftClusterPort": {
            "Default": 5440,
            "MinValue": 0,
            "MaxValue": 65535,
            "Type": "Number",
            "Description": "The port number on which Amazon Redshift cluster accepts incoming connections."
        },
        "ClassificationRedshiftClusterNodeType": {
            "Default": "dc2.large",
            "Type": "String",
            "AllowedValues": ["ds2.xlarge", "ds2.8xlarge", "dc1.large", "dc1.8xlarge", "dc2.large", "dc2.8xlarge", "ra3.xlplus", "ra3.4xlarge", "ra3.16xlarge"],
            "Description": "The node type to be provisioned for Amazon Redshift cluster. For information about node types, go to https://docs.aws.amazon.com/redshift/latest/mgmt/working-with-clusters.html#how-many-nodes."
        },
        "ClassificationRedshiftClusterVpcId": {
            "Type": "AWS::EC2::VPC::Id",
            "Description": "The ID of the VPC for the security group associated with Amazon Redshift cluster."
        },
        "ClassificationRedshiftClusterSubnetId": {
            "Type": "AWS::EC2::Subnet::Id",
            "Description": "VPC subnet ID associated with Amazon Redshift cluster. In this walk-through, we will use single subnet for Amazon Redshift cluster."
        },
        "QuickSightRegion": {
            "Default": "us-east-1",
            "Type": "String",
            "AllowedValues": ["us-east-1", "us-east-2", "us-west-2", "eu-west-1", "eu-west-2", "eu-central-1"],
            "Description": "Region which will host Amazon QuickSight."
        },
        "LambdaCodeS3Bucket": {
            "Type": "String",
            "AllowedPattern": "^[0-9A-Za-z\\.\\-_]*(?<!\\.)$",
            "Description": "An Amazon S3 bucket in the same AWS Region as your Lambda function."
        },
        "LambdaCodeS3Key": {
            "Default": "lambda_code.zip",
            "Type": "String",
            "MinLength": 1,
            "Description": "The Amazon S3 key of the deployment package."
        }
    },
    "Mappings": {
        "KinesisFirehoseIPRange": {
            "us-east-1": {
                "CIDRBlock": "52.70.63.192/27"
            },
            "us-east-2": {
                "CIDRBlock": "13.58.135.96/27"
            },
            "us-west-2": {
                "CIDRBlock": "52.89.255.224/27"
            },
            "us-west-1": {
                "CIDRBlock": "13.57.135.192/27"
            },
            "eu-west-1": {
                "CIDRBlock": "52.19.239.192/27"
            },
            "eu-west-2": {
                "CIDRBlock": "18.130.1.96/27"
            },
            "eu-west-3": {
                "CIDRBlock": "35.180.1.96/27"
            },
            "eu-central-1": {
                "CIDRBlock": "35.158.127.160/27"
            },
            "eu-south-1": {
                "CIDRBlock": "15.161.135.128/27"
            },
            "eu-north-1": {
                "CIDRBlock": "13.53.63.224/27"
            },
            "ap-east-1": {
                "CIDRBlock": "18.162.221.32/27"
            },
            "ap-northeast-1": {
                "CIDRBlock": "13.113.196.224/27"
            },
            "ap-northeast-2": {
                "CIDRBlock": "13.209.1.64/27"
            },
            "ap-northeast-3": {
                "CIDRBlock": "13.208.177.192/27"
            },
            "ap-southeast-1": {
                "CIDRBlock": "13.228.64.192/27"
            },
            "ap-southeast-2": {
                "CIDRBlock": "13.210.67.224/27"
            },
            "ap-south-1": {
                "CIDRBlock": "13.232.67.32/27"
            },
            "ca-central-1": {
                "CIDRBlock": "35.183.92.128/27"
            },
            "sa-east-1": {
                "CIDRBlock": "18.228.1.128/27"
            },
            "cn-north-1": {
                "CIDRBlock": "52.81.151.32/27"
            },
            "cn-northwest-1": {
                "CIDRBlock": "161.189.23.64/27"
            },
            "me-south-1": {
                "CIDRBlock": "15.185.91.0/27"
            },
            "af-south-1": {
                "CIDRBlock": "13.244.121.224/27"
            },
            "us-gov-east-1": {
                "CIDRBlock": "18.253.138.96/27"
            },
            "us-gov-west-1": {
                "CIDRBlock": "52.61.204.160/27"
            }
        },
        "QuickSightIPRange": {
            "us-east-1": {
                "CIDRBlock": "52.23.63.224/27"
            },
            "us-east-2": {
                "CIDRBlock": "52.15.247.160/27"
            },
            "us-west-2": {
                "CIDRBlock": "54.70.204.128/27"
            },
            "eu-west-1": {
                "CIDRBlock": "52.210.255.224/27"
            },
            "eu-west-2": {
                "CIDRBlock": "35.177.218.0/27"
            },
            "eu-central-1": {
                "CIDRBlock": "35.158.127.192/27"
            }
        }
    },
    "Outputs": {
        "StackArn": {
            "Description": "Use this as the stack_arn in your cloud_formation_deployment_stack override.",
            "Value": {
                "Ref": "AWS::StackId"
            }
        }
    },
    "Resources": {
        "TicketClassifierLambdaFunction": {
            "Type": "AWS::Lambda::Function",
            "Properties": {
                "Code": {
                    "S3Bucket": {
                        "Ref": "LambdaCodeS3Bucket"
                    },
                    "S3Key": {
                        "Ref": "LambdaCodeS3Key"
                    }
                },
                "MemorySize": 128,
                "Environment": {
                    "Variables": {
                        "TICKETHANDLER_FUNCTION_ARN": {
                            "Fn::GetAtt": "TicketHandlerLambdaFunction.Arn"
                        },
                        "COMPREHEND_TICKET_OPERATION_CLASSIFIER_ARN": {
                            "Fn::Sub": [
                                "arn:aws:comprehend:${AWS::Region}:${AWS::AccountId}:document-classifier-endpoint/${endpoint}",
                                {
                                    "endpoint": {
                                        "Ref": "ComprehendTicketOperationClassifierEndpoint"
                                    }
                                }
                            ]
                        },
                        "COMPREHEND_TICKET_RESOURCE_CLASSIFIER_ARN": {
                            "Fn::Sub": [
                                "arn:aws:comprehend:${AWS::Region}:${AWS::AccountId}:document-classifier-endpoint/${endpoint}",
                                {
                                    "endpoint": {
                                        "Ref": "ComprehendTicketResourceClassifierEndpoint"
                                    }
                                }
                            ]
                        },
                        "OPERATION_SCORE_THRESHOLD": {
                            "Ref": "OperationScoreThreshold"
                        },
                        "RESOURCE_SCORE_THRESHOLD": {
                            "Ref": "ResourceScoreThreshold"
                        },
                        "KINESIS_FIREHOSE_DELIVERY_STREAM_NAME": {
                            "Ref": "ClassificationDeliveryStreamName"
                        }
                    }
                },
                "Handler": "ticket_classifier.main",
                "Role": {
                    "Fn::GetAtt": [
                        "TicketClassifierLambdaRole",
                        "Arn"
                    ]
                },
                "Timeout": 20,
                "Runtime": "python3.9"
            }
        },
        "TicketClassifierLambdaRole": {
            "Type": "AWS::IAM::Role",
            "Properties": {
                "Policies": [
                    {
                        "PolicyName": "CloudWatchLogs",
                        "PolicyDocument": {
                            "Version": "2012-10-17",
                            "Statement": [
                                {
                                    "Action": [
                                        "logs:CreateLogGroup",
                                        "logs:CreateLogStream",
                                        "logs:PutLogEvents"
                                    ],
                                    "Resource": "*",
                                    "Effect": "Allow"
                                }
                            ]
                        }
                    },
                    {
                        "PolicyName": "Firehose",
                        "PolicyDocument": {
                            "Version": "2012-10-17",
                            "Statement": [
                                {
                                    "Action": [
                                        "firehose:PutRecord"
                                    ],
                                    "Resource": {
                                        "Fn::GetAtt": "ClassificationDeliveryStream.Arn"
                                    },
                                    "Effect": "Allow"
                                }
                            ]
                        }
                    },
                    {
                        "PolicyName": "LambdaExecution",
                        "PolicyDocument": {
                            "Version": "2012-10-17",
                            "Statement": [
                                {
                                    "Action": [
                                        "lambda:InvokeFunction"
                                    ],
                                    "Resource": {
                                        "Fn::GetAtt": "TicketHandlerLambdaFunction.Arn"
                                    },
                                    "Effect": "Allow"
                                }
                            ]
                        }
                    },
                    {
                        "PolicyName": "Comprehend",
                        "PolicyDocument": {
                            "Version": "2012-10-17",
                            "Statement": [
                                {
                                    "Action": [
                                        "comprehend:ClassifyDocument"
                                    ],
                                    "Resource": [
                                        {
                                            "Fn::Sub": [
                                                "arn:aws:comprehend:${AWS::Region}:${AWS::AccountId}:document-classifier-endpoint/${endpoint}",
                                                {
                                                    "endpoint": {
                                                        "Ref": "ComprehendTicketOperationClassifierEndpoint"
                                                    }
                                                }
                                            ]
                                        },
                                        {
                                            "Fn::Sub": [
                                                "arn:aws:comprehend:${AWS::Region}:${AWS::AccountId}:document-classifier-endpoint/${endpoint}",
                                                {
                                                    "endpoint": {
                                                        "Ref": "ComprehendTicketResourceClassifierEndpoint"
                                                    }
                                                }
                                            ]
                                        }
                                    ],
                                    "Effect": "Allow"
                                }
                            ]
                        }
                    }
                ],
                "AssumeRolePolicyDocument": {
                    "Version": "2012-10-17",
                    "Statement": [
                        {
                            "Action": [
                                "sts:AssumeRole"
                            ],
                            "Effect": "Allow",
                            "Principal": {
                                "Service": [
                                    "lambda.amazonaws.com"
                                ]
                            }
                        }
                    ]
                }
            }
        },
        "TicketClassifierLambdaLogGroup": {
            "Type": "AWS::Logs::LogGroup",
            "Properties": {
                "LogGroupName": {
                    "Fn::Sub": "/aws/lambda/${TicketClassifierLambdaFunction}"
                }
            },
            "DependsOn": "TicketClassifierLambdaFunction"
        },
        "TicketClassifierLambdaTooManyErrorsAlarm": {
            "Type": "AWS::CloudWatch::Alarm",
            "Properties": {
                "EvaluationPeriods": 1,
                "TreatMissingData": "notBreaching",
                "Dimensions": [
                    {
                        "Name": "FunctionName",
                        "Value": {
                            "Ref": "TicketClassifierLambdaFunction"
                        }
                    }
                ],
                "AlarmDescription": "TicketClassifier Lambda Function Errors > 0",
                "Namespace": "AWS/Lambda",
                "Period": 60,
                "ComparisonOperator": "GreaterThanThreshold",
                "Statistic": "Sum",
                "Threshold": 0,
                "MetricName": "Errors"
            }
        },
        "TicketHandlerLambdaFunction": {
            "Type": "AWS::Lambda::Function",
            "Properties": {
                "Code": {
                    "S3Bucket": {
                        "Ref": "LambdaCodeS3Bucket"
                    },
                    "S3Key": {
                        "Ref": "LambdaCodeS3Key"
                    }
                },
                "MemorySize": 128,
                "Environment": {
                    "Variables": {
                        "CLASSIFICATION_STREAM_ARN": {
                            "Fn::GetAtt": [
                                "ClassificationDeliveryStream",
                                "Arn"
                            ]
                        }
                    }
                },
                "Handler": "ticket_handler.main",
                "Role": {
                    "Fn::GetAtt": [
                        "TicketHandlerLambdaRole",
                        "Arn"
                    ]
                },
                "Timeout": 180,
                "Runtime": "python3.6"
            }
        },
        "TicketHandlerLambdaTooManyErrorsAlarm": {
            "Type": "AWS::CloudWatch::Alarm",
            "Properties": {
                "EvaluationPeriods": 2,
                "TreatMissingData": "notBreaching",
                "Dimensions": [
                    {
                        "Name": "FunctionName",
                        "Value": {
                            "Ref": "TicketHandlerLambdaFunction"
                        }
                    }
                ],
                "AlarmDescription": "TicketHandler Lambda Function Errors > 0",
                "Namespace": "AWS/Lambda",
                "Period": 60,
                "ComparisonOperator": "GreaterThanThreshold",
                "Statistic": "Sum",
                "Threshold": 0,
                "MetricName": "Errors"
            }
        },
        "TicketHandlerLambdaRole": {
            "Type": "AWS::IAM::Role",
            "Properties": {
                "Policies": [
                    {
                        "PolicyName": "CWLogs",
                        "PolicyDocument": {
                            "Version": "2012-10-17",
                            "Statement": [
                                {
                                    "Action": [
                                        "logs:CreateLogGroup",
                                        "logs:CreateLogStream",
                                        "logs:PutLogEvents"
                                    ],
                                    "Resource": "*",
                                    "Effect": "Allow"
                                }
                            ]
                        }
                    }
                ],
                "AssumeRolePolicyDocument": {
                    "Version": "2012-10-17",
                    "Statement": [
                        {
                            "Action": [
                                "sts:AssumeRole"
                            ],
                            "Effect": "Allow",
                            "Principal": {
                                "Service": [
                                    "lambda.amazonaws.com"
                                ]
                            }
                        }
                    ]
                }
            }
        },
        "TicketHandlerLambdaLogGroup": {
            "Type": "AWS::Logs::LogGroup",
            "Properties": {
                "LogGroupName": {
                    "Fn::Sub": "/aws/lambda/${TicketHandlerLambdaFunction}"
                }
            },
            "DependsOn": "TicketHandlerLambdaFunction"
        },
        "ClassificationRedshiftCluster": {
            "Type": "AWS::Redshift::Cluster",
            "Properties": {
                "AllowVersionUpgrade": true,
                "DBName": {
                    "Ref": "ClassificationRedshiftClusterDBName"
                },
                "Port": {
                    "Ref": "ClassificationRedshiftClusterPort"
                },
                "MasterUsername": {
                    "Ref": "ClassificationRedshiftClusterUsername"
                },
                "MasterUserPassword": {
                    "Fn::Sub": "{{resolve:secretsmanager:${ClassificationRedshiftClusterPasswordSecretName}:SecretString:password}}"
                },
                "NodeType": {
                    "Ref": "ClassificationRedshiftClusterNodeType"
                },
                "ClusterType": "single-node",
                "ClusterParameterGroupName": {
                    "Ref": "ClassificationRedshiftClusterParameterGroup"
                },
                "ClusterSubnetGroupName": {
                    "Ref": "ClassificationRedshiftClusterSubnetGroup"
                },
                "PubliclyAccessible": true,
                "VpcSecurityGroupIds": [
                    {
                        "Ref": "ClassificationRedshiftClusterSecurityGroup"
                    }
                ],
                "IamRoles": [
                    {
                        "Fn::GetAtt": "ClassificationDeliveryStreamRole.Arn"
                    }
                ],
                "Encrypted": true
            }
        },
        "ClassificationRedshiftClusterParameterGroup": {
            "Type": "AWS::Redshift::ClusterParameterGroup",
            "Properties": {
                "Description": "Parameter Group for Classification Redshift Cluster.",
                "ParameterGroupFamily": "redshift-1.0",
                "Parameters": [
                    {
                        "ParameterName" : "require_ssl",
                        "ParameterValue" : "true"
                    },
                    {
                        "ParameterName" : "enable_user_activity_logging",
                        "ParameterValue" : "true"
                    }
                ]
            }
        },
        "ClassificationRedshiftClusterSubnetGroup": {
            "Type": "AWS::Redshift::ClusterSubnetGroup",
            "Properties": {
                "Description": "ClassificationRedshiftClusterSubnetGroup",
                "SubnetIds": [
                    {
                        "Ref": "ClassificationRedshiftClusterSubnetId"
                    }
                ]
            }
        },
        "ClassificationRedshiftClusterSecurityGroup": {
            "Type": "AWS::EC2::SecurityGroup",
            "Properties": {
                "GroupDescription": "Allow Kinesis Firehose to access Redshift cluster.",
                "VpcId": {
                    "Ref": "ClassificationRedshiftClusterVpcId"
                },
                "SecurityGroupIngress": [
                    {
                        "IpProtocol": "tcp",
                        "FromPort": {
                            "Ref": "ClassificationRedshiftClusterPort"
                        },
                        "ToPort": {
                            "Ref": "ClassificationRedshiftClusterPort"
                        },
                        "CidrIp": { "Fn::FindInMap" : [ "KinesisFirehoseIPRange", { "Ref" : "AWS::Region" }, "CIDRBlock"] },
                        "Description": "Kinesis Firehose IP Ranges for Redshift access"
                    },
                    {
                        "IpProtocol": "tcp",
                        "FromPort": {
                            "Ref": "ClassificationRedshiftClusterPort"
                        },
                        "ToPort": {
                            "Ref": "ClassificationRedshiftClusterPort"
                        },
                        "CidrIp": { "Fn::FindInMap" : [ "QuickSightIPRange", { "Ref" : "QuickSightRegion" }, "CIDRBlock"] },
                        "Description": "QuickSight IP Ranges for Redshift access"
                    }
                ],
                "SecurityGroupEgress": [
                ]
            }
        },
        "ClassificationDeliveryStreamS3Bucket": {
            "Type": "AWS::S3::Bucket",
            "Properties": {
                "BucketEncryption": {
                    "ServerSideEncryptionConfiguration": [
                        {
                            "BucketKeyEnabled": true,
                            "ServerSideEncryptionByDefault": {
                                "SSEAlgorithm": "AES256"
                            }
                        }
                    ]
                },
                "LifecycleConfiguration": {
                    "Rules": [
                        {
                            "Id": "Delete",
                            "Status": "Enabled",
                            "ExpirationInDays": 1,
                            "NoncurrentVersionExpiration": {
                                "NoncurrentDays": 1
                            },
                            "Prefix": "kinesisfirehose"
                        }
                    ]
                },
                "LoggingConfiguration": {
                    "LogFilePrefix": "logs"
                },
                "PublicAccessBlockConfiguration": {
                    "BlockPublicAcls": true,
                    "BlockPublicPolicy": true,
                    "IgnorePublicAcls": true,
                    "RestrictPublicBuckets": true
                }
            }
        },
        "ClassificationDeliveryStreamS3BucketPolicy": {
            "Type": "AWS::S3::BucketPolicy",
            "Properties": {
                "Bucket": {
                    "Ref": "ClassificationDeliveryStreamS3Bucket"
                },
                "PolicyDocument": {
                    "Id": "SecureTransport",
                    "Version": "2012-10-17",
                    "Statement": [
                        {
                            "Sid": "AllowSSLRequestsOnly",
                            "Action": "s3:*",
                            "Effect": "Deny",
                            "Resource": [
                                {
                                    "Fn::Sub": "arn:aws:s3:::${ClassificationDeliveryStreamS3Bucket}"
                                },
                                {
                                    "Fn::Sub": "arn:aws:s3:::${ClassificationDeliveryStreamS3Bucket}/*"
                                }
                            ],
                            "Condition": {
                                "Bool": {
                                "aws:SecureTransport": "false"
                                }
                            },
                            "Principal": "*"
                        }
                    ]
                }
            }
        },
        "ClassificationDeliveryStream": {
            "Type": "AWS::KinesisFirehose::DeliveryStream",
            "Properties": {
                "DeliveryStreamEncryptionConfigurationInput": {
                    "KeyType": "AWS_OWNED_CMK"
                },
                "DeliveryStreamName": {
                    "Ref": "ClassificationDeliveryStreamName"
                },
                "DeliveryStreamType": "DirectPut",
                "RedshiftDestinationConfiguration": {
                    "ClusterJDBCURL": {
                        "Fn::Sub": "jdbc:redshift://${ClassificationRedshiftCluster.Endpoint.Address}:${ClassificationRedshiftClusterPort}/${ClassificationRedshiftClusterDBName}"
                    },
                    "CopyCommand": {
                        "CopyOptions": "FORMAT AS JSON 'auto' GZIP",
                        "DataTableColumns": "id,title,description,creation_time,operation,resource",
                        "DataTableName": "tickets"
                    },
                    "Password": {
                        "Fn::Sub": "{{resolve:secretsmanager:${ClassificationRedshiftClusterPasswordSecretName}:SecretString:password}}"
                    },
                    "RoleARN": {
                        "Fn::GetAtt": [
                            "ClassificationDeliveryStreamRole",
                            "Arn"
                        ]
                    },
                    "Username": {
                        "Ref": "ClassificationRedshiftClusterUsername"
                    },
                    "S3Configuration": {
                        "BucketARN": {
                            "Fn::GetAtt": [
                                "ClassificationDeliveryStreamS3Bucket",
                                "Arn"
                            ]
                        },
                        "CompressionFormat": "GZIP",
                        "Prefix": "kinesisfirehose",
                        "RoleARN": {
                            "Fn::GetAtt": [
                                "ClassificationDeliveryStreamRole",
                                "Arn"
                            ]
                        }
                    },
                    "CloudWatchLoggingOptions": {
                        "Enabled": true,
                        "LogGroupName": {
                            "Ref": "ClassificationDeliveryStreamLogGroup"
                        },
                        "LogStreamName": {
                            "Ref": "ClassificationDeliveryStreamLogStream"
                        }
                    }
                }
            }
        },
        "ClassificationDeliveryStreamLogGroup": {
            "Type": "AWS::Logs::LogGroup",
            "Properties": {
                "LogGroupName": {
                    "Fn::Sub": "/aws/kinesisfirehose/${ClassificationDeliveryStreamName}"
                }
            }
        },
        "ClassificationDeliveryStreamLogStream": {
            "Type": "AWS::Logs::LogStream",
            "Properties": {
                "LogGroupName": {
                    "Ref": "ClassificationDeliveryStreamLogGroup"
                }
            }
        },
        "ClassificationDeliveryStreamRole": {
            "Type": "AWS::IAM::Role",
            "Properties": {
                "Policies": [
                    {
                        "PolicyName": "CloudWatchLogs",
                        "PolicyDocument": {
                            "Version": "2012-10-17",
                            "Statement": [
                                {
                                    "Action": [
                                        "logs:CreateLogGroup",
                                        "logs:CreateLogStream",
                                        "logs:PutLogEvents"
                                    ],
                                    "Resource": "*",
                                    "Effect": "Allow"
                                }
                            ]
                        }
                    },
                    {
                        "PolicyName": "S3",
                        "PolicyDocument": {
                            "Version": "2012-10-17",
                            "Statement": [
                                {
                                    "Effect": "Allow",
                                    "Action": [
                                        "s3:AbortMultipartUpload",
                                        "s3:GetBucketLocation",
                                        "s3:GetObject",
                                        "s3:ListBucket",
                                        "s3:ListBucketMultipartUploads",
                                        "s3:PutObject"
                                    ],
                                    "Resource": [
                                        {
                                            "Fn::GetAtt": [
                                                "ClassificationDeliveryStreamS3Bucket",
                                                "Arn"
                                            ]
                                        },
                                        {
                                            "Fn::Sub": "${ClassificationDeliveryStreamS3Bucket.Arn}/*"
                                        }
                                    ]
                                }
                            ]
                        }
                    },
                    {
                        "PolicyName": "Kinesis",
                        "PolicyDocument": {
                            "Version": "2012-10-17",
                            "Statement": [
                                {
                                    "Effect": "Allow",
                                    "Action": [
                                        "kinesis:DescribeStream",
                                        "kinesis:GetShardIterator",
                                        "kinesis:GetRecords",
                                        "kinesis:ListShards"
                                    ],
                                    "Resource": [
                                        {
                                            "Fn::Sub": "arn:aws:firehose:${AWS::Region}:${AWS::AccountId}:deliverystream/${ClassificationDeliveryStreamName}"
                                        }
                                    ]
                                }
                            ]
                        }
                    }
                ],
                "AssumeRolePolicyDocument": {
                    "Version": "2012-10-17",
                    "Statement": [
                        {
                            "Action": [
                                "sts:AssumeRole"
                            ],
                            "Effect": "Allow",
                            "Principal": {
                                "Service": [
                                    "firehose.amazonaws.com"
                                ]
                            }
                        }
                    ]
                }
            }
        }
    }
}