{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "AWS 4Insights  - CloudFormation Template",
    "Parameters": {
        "AppCustomerName": {
            "Description": "Customer Name",
            "Type": "String",
            "MaxLength": "16",
            "MinLength": "3",
            "Default": "YourCompanyName"
        },
        "AppAdminPassword": {
            "AllowedPattern": "^(?=.*?[A-Z])(?=(.*[a-z]){1,})(?=(.*[\\d]){1,})(?=(.*[\\W]){1,})(?!.*\\s).{8,}$",
            "ConstraintDescription": "Must contain alphanumeric characters, uppercase letters, lowercase letters, at least one number and at least one special character",
            "Description": "The application admin account password.",
            "MaxLength": "41",
            "MinLength": "8",
            "NoEcho": "true",
            "Type": "String"
        },
        "InstanceType": {
            "Description": "EC2 type -  4Insights WebServer Instance (App)",
            "Type": "String",
            "Default": "m4.large",
            "AllowedValues": [
                "t2.micro",
                "t2.nano",
                "t2.micro",
                "t2.small",
                "t2.medium",
                "t2.large",
                "m1.small",
                "m1.medium",
                "m1.large",
                "m1.xlarge",
                "m2.xlarge",
                "m2.2xlarge",
                "m2.4xlarge",
                "m3.medium",
                "m3.large",
                "m3.xlarge",
                "m3.2xlarge",
                "m4.large",
                "m4.xlarge",
                "m4.2xlarge",
                "m4.4xlarge",
                "m4.10xlarge",
                "c1.medium",
                "c1.xlarge",
                "c3.large",
                "c3.xlarge",
                "c3.2xlarge",
                "c3.4xlarge",
                "c3.8xlarge",
                "c4.large",
                "c4.xlarge",
                "c4.2xlarge",
                "c4.4xlarge",
                "c4.8xlarge",
                "g2.2xlarge",
                "g2.8xlarge",
                "r3.large",
                "r3.xlarge",
                "r3.2xlarge",
                "r3.4xlarge",
                "r3.8xlarge",
                "i2.xlarge",
                "i2.2xlarge",
                "i2.4xlarge",
                "i2.8xlarge",
                "d2.xlarge",
                "d2.2xlarge",
                "d2.4xlarge",
                "d2.8xlarge",
                "hi1.4xlarge",
                "hs1.8xlarge",
                "cr1.8xlarge",
                "cc2.8xlarge",
                "cg1.4xlarge"
            ],
            "ConstraintDescription": "Must select a valid instance type!"
        },
        "EC2KeyName": {
            "Description": "EC2 KeyPair - Allow SSH access to the EC2 created instance.",
            "Type": "AWS::EC2::KeyPair::KeyName",
            "ConstraintDescription": "must be the name of an existing EC2 KeyPair."
        },
        "SSHLocation": {
            "Description": "IP range to allow SSH to the EC2 instance.",
            "Type": "String",
            "MinLength": "9",
            "MaxLength": "18",
            "Default": "0.0.0.0/0",
            "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})",
            "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x."
        },
        "DatabaseInstanceType": {
            "Default": "db.t2.micro",
            "AllowedValues": [
                "db.t2.micro",
                "db.t2.small",
                "db.t2.medium",
                "db.t2.large",
                "db.m4.large",
                "db.m4.xlarge",
                "db.m4.2xlarge",
                "db.m4.4xlarge",
                "db.m4.10xlarge",
                "db.r3.large",
                "db.r3.xlarge",
                "db.r3.2xlarge",
                "db.r3.4xlarge",
                "db.r3.8xlarge"
            ],
            "Description": "The instance type to use for the database.",
            "Type": "String"
        },
        "DatabaseName": {
            "Default": "fourinsights",
            "AllowedPattern": "[a-zA-Z0-9]+",
            "ConstraintDescription": "must contain only alphanumeric characters.",
            "Description": "The database instance name. (default: fourinsights)",
            "MaxLength": "16",
            "MinLength": "3",
            "Type": "String"
        },
        "DatabaseUsername": {
            "Default": "admin",
            "AllowedPattern": "[a-zA-Z0-9]+",
            "ConstraintDescription": "must contain only alphanumeric characters.",
            "Description": "The database admin account user name. (default: admin)",
            "MaxLength": "16",
            "MinLength": "1",
            "Type": "String"
        },
        "DatabasePassword": {
            "AllowedPattern": "^(?=.*?[A-Z])(?=(.*[a-z]){1,})(?=(.*[\\d]){1,})(?=(.*[\\W]){1,})(?!.*\\s).{8,}$",
            "ConstraintDescription": "Must contain alphanumeric characters, uppercase letters, lowercase letters, at least one number and at least one special character",
            "Description": "The database admin account password.",
            "MaxLength": "41",
            "MinLength": "8",
            "NoEcho": "true",
            "Type": "String"
        },
        "MultiAZDatabase": {
            "Default": "false",
            "Description": "Create a multi-AZ MySQL Amazon RDS database instance (default: false).",
            "Type": "String",
            "AllowedValues": [
                "true",
                "false"
            ],
            "ConstraintDescription": "must be either true or false."
        },
        "DBAllocatedStorage": {
            "Default": "5",
            "Description": "The size of the database - default: 5GB (from 5 to 6144 GB).",
            "Type": "Number",
            "MinValue": "5",
            "MaxValue": "6144",
            "ConstraintDescription": "must be between 5 and 6144Gb."
        },
        "DatabaseBackupRetentionPeriod": {
            "Type": "String",
            "Default": 7,
            "AllowedValues": [
                0,
                1,
                7
            ],
            "Description": "The database backup retention period in days - default: 7 (from 0 to 7 days)."
        },
        "EC2VPC": {
            "Description": "VPC to deploy your EC2 Instance in.",
            "Type": "AWS::EC2::VPC::Id"
        },
        "EC2Subnet": {
            "Description": "Select (1) subnet to associate with the EC2 instance. Make sure to choose the subnet within the same VPC chosen above.",
            "Type": "List<AWS::EC2::Subnet::Id>"
        },
        "DatabaseSubnets": {
            "Description": "Select (2) PRIVATE subnets to place RDS database into. Make sure to choose it within the same EC2 VPC instance chosen above.",
            "Type": "List<AWS::EC2::Subnet::Id>"
        },
        "DBSnapshotIdentifier": {
            "Description": "SnapshotName to restore into the new RDS MySQL instance that will be created. (Optional) ",
            "Type": "String",
            "Default": ""
        },
        "DataWarehouseBucketName": {
            "Default": "customername.datawarehouse",
            "AllowedPattern": "^[0-9a-z\\.\\-/]{3,63}$",
            "ConstraintDescription": "enter a valid bucket name",
            "Description": "The bucket name",
            "MaxLength": "63",
            "MinLength": "3",
            "Type": "String"
        },
        "RedshiftDatabaseName": {
            "Default": "datawarehouse",
            "AllowedPattern": "[a-zA-Z0-9]+",
            "ConstraintDescription": "must contain only alphanumeric characters.",
            "Description": "The database instance name. (default: datawarehouse)",
            "MaxLength": "16",
            "MinLength": "3",
            "Type": "String"
        },
        "RedshiftDatabaseUsername": {
            "Default": "admin",
            "AllowedPattern": "[a-zA-Z0-9]+",
            "ConstraintDescription": "must contain only alphanumeric characters.",
            "Description": "The database admin account user name. (default: admin)",
            "MaxLength": "16",
            "MinLength": "1",
            "Type": "String"
        },
        "RedshiftDatabasePassword": {
            "AllowedPattern": "^(?=.*?[A-Z])(?=(.*[a-z]){1,})(?=(.*[\\d]){1,})(?=(.*[\\W]){1,})(?!.*\\s).{8,}$",
            "ConstraintDescription": "Must contain alphanumeric characters, uppercase letters, lowercase letters, at least one number and at least one special character",
            "Description": "The database admin account password.",
            "MaxLength": "41",
            "MinLength": "8",
            "NoEcho": "true",
            "Type": "String"
        },
        "RedshiftNodeType": {
            "Default": "dc1.large",
            "AllowedValues": [
                "dc1.large",
                "dc1.8xlarge",
                "ds2.xlarge",
                "ds2.8xlarge",
                "ds1.xlarge",
                "ds1.8xlarge"
            ],
            "Description": "The instance type to use for the redshift.",
            "Type": "String"
        },
        "RedshiftClusterType": {
            "Default": "single-node",
            "AllowedValues": [
                "single-node",
                "multi-node"
            ],
            "Description": "The type of cluster",
            "Type": "String"
        },
        "RedshiftNumberOfNodes": {
            "Default": 1,
            "Description": "The number of compute nodes in the cluster, only for the \"multi-node\" (min: 2, max: 32)",
            "MaxValue": 32,
            "MinValue": 1,
            "Type": "Number"
        },
        "RedshiftSubnets": {
            "Description": "Select (1) subnet to associate with the redshift. Make sure to choose the subnet within the same VPC chosen above.",
            "Type": "List<AWS::EC2::Subnet::Id>"
        },
        "DataLakeBucketName": {
            "Default": "customername.datalake",
            "AllowedPattern": "^[0-9a-z\\.\\-/]{3,63}$",
            "ConstraintDescription": "enter a valid bucket name",
            "Description": "The bucket name",
            "MaxLength": "63",
            "MinLength": "3",
            "Type": "String"
        },
        "AthenaDatabaseName": {
            "Default": "datalake",
            "AllowedPattern": "[a-zA-Z0-9]+",
            "ConstraintDescription": "must contain only alphanumeric characters.",
            "Description": "The database instance name. (default: datalake)",
            "MaxLength": "16",
            "MinLength": "3",
            "Type": "String"
        },
        "RedshiftPubliclyAccessible": {
            "Default": "false",
            "AllowedValues": [
                "true",
                "false"
            ],
            "Description": "Publicly Accessible",
            "Type": "String"
        }
    },
    "Conditions": {
        "UseDbSnapshot": {
            "Fn::Not": [{
                "Fn::Equals": [{
                        "Ref": "DBSnapshotIdentifier"
                    },
                    ""
                ]
            }]
        },
        "UseRedshiftNumberOfNodes": {
            "Fn::Equals": [{
                    "Ref": "RedshiftClusterType"
                },
                "multi-node"
            ]
        }
    },
    "Mappings": {
        "AWSInstanceType2Arch": {
            "t2.nano": {
                "Arch": "HVM64"
            },
            "t2.micro": {
                "Arch": "HVM64"
            },
            "t2.small": {
                "Arch": "HVM64"
            },
            "t2.medium": {
                "Arch": "HVM64"
            },
            "t2.large": {
                "Arch": "HVM64"
            },
            "t2.xlarge": {
                "Arch": "HVM64"
            },
            "t2.2xlarge": {
                "Arch": "HVM64"
            },
            "m3.medium": {
                "Arch": "HVM64"
            },
            "m3.large": {
                "Arch": "HVM64"
            },
            "m3.xlarge": {
                "Arch": "HVM64"
            },
            "m3.2xlarge": {
                "Arch": "HVM64"
            },
            "m4.large": {
                "Arch": "HVM64"
            },
            "m4.xlarge": {
                "Arch": "HVM64"
            },
            "m4.2xlarge": {
                "Arch": "HVM64"
            },
            "m4.4xlarge": {
                "Arch": "HVM64"
            },
            "m4.10xlarge": {
                "Arch": "HVM64"
            },
            "m4.16xlarge": {
                "Arch": "HVM64"
            }
        },
        "AWSInstanceType2NATArch": {
            "t2.nano": {
                "Arch": "NATHVM64"
            },
            "t2.micro": {
                "Arch": "NATHVM64"
            },
            "t2.small": {
                "Arch": "NATHVM64"
            },
            "t2.medium": {
                "Arch": "NATHVM64"
            },
            "t2.large": {
                "Arch": "NATHVM64"
            },
            "t2.xlarge": {
                "Arch": "NATPV64"
            },
            "t2.2xlarge": {
                "Arch": "NATPV64"
            },
            "m3.medium": {
                "Arch": "NATPV64"
            },
            "m3.large": {
                "Arch": "NATPV64"
            },
            "m3.xlarge": {
                "Arch": "NATPV64"
            },
            "m3.2xlarge": {
                "Arch": "NATPV64"
            },
            "m4.large": {
                "Arch": "NATPV64"
            },
            "m4.xlarge": {
                "Arch": "NATHVM64"
            },
            "m4.2xlarge": {
                "Arch": "NATHVM64"
            },
            "m4.4xlarge": {
                "Arch": "NATHVM64"
            },
            "m4.10xlarge": {
                "Arch": "NATHVM64"
            },
            "m4.16xlarge": {
                "Arch": "NATHVM64"
            }
        },
        "AWSRegionArch2AMI": {
            "us-east-1": {
                "HVM64": "ami-0ff8a91507f77f867",
                "HVMG2": "ami-0a584ac55a7631c0c"
            },
            "us-west-2": {
                "HVM64": "ami-a0cfeed8",
                "HVMG2": "ami-0e09505bc235aa82d"
            },
            "us-west-1": {
                "HVM64": "ami-0bdb828fd58c52235",
                "HVMG2": "ami-066ee5fd4a9ef77f1"
            },
            "eu-west-1": {
                "HVM64": "ami-047bb4163c506cd98",
                "HVMG2": "ami-0a7c483d527806435"
            },
            "eu-west-2": {
                "HVM64": "ami-f976839e",
                "HVMG2": "NOT_SUPPORTED"
            },
            "eu-west-3": {
                "HVM64": "ami-0ebc281c20e89ba4b",
                "HVMG2": "NOT_SUPPORTED"
            },
            "eu-central-1": {
                "HVM64": "ami-0233214e13e500f77",
                "HVMG2": "ami-06223d46a6d0661c7"
            },
            "ap-northeast-1": {
                "HVM64": "ami-06cd52961ce9f0d85",
                "HVMG2": "ami-053cdd503598e4a9d"
            },
            "ap-northeast-2": {
                "HVM64": "ami-0a10b2721688ce9d2",
                "HVMG2": "NOT_SUPPORTED"
            },
            "ap-northeast-3": {
                "HVM64": "ami-0d98120a9fb693f07",
                "HVMG2": "NOT_SUPPORTED"
            },
            "ap-southeast-1": {
                "HVM64": "ami-08569b978cc4dfa10",
                "HVMG2": "ami-0be9df32ae9f92309"
            },
            "ap-southeast-2": {
                "HVM64": "ami-09b42976632b27e9b",
                "HVMG2": "ami-0a9ce9fecc3d1daf8"
            },
            "ap-south-1": {
                "HVM64": "ami-0912f71e06545ad88",
                "HVMG2": "ami-097b15e89dbdcfcf4"
            },
            "us-east-2": {
                "HVM64": "ami-0b59bfac6be064b78",
                "HVMG2": "NOT_SUPPORTED"
            },
            "ca-central-1": {
                "HVM64": "ami-0b18956f",
                "HVMG2": "NOT_SUPPORTED"
            },
            "sa-east-1": {
                "HVM64": "ami-07b14488da8ea02a0",
                "HVMG2": "NOT_SUPPORTED"
            },
            "cn-north-1": {
                "HVM64": "ami-0a4eaf6c4454eda75",
                "HVMG2": "NOT_SUPPORTED"
            },
            "cn-northwest-1": {
                "HVM64": "ami-6b6a7d09",
                "HVMG2": "NOT_SUPPORTED"
            }
        }
    },
    "Metadata": {
        "AWS::CloudFormation::Interface": {
            "ParameterGroups": [{
                    "Label": {
                        "default": " [   4Insights  ]   EC2 / RDS Configuration  "
                    },
                    "Parameters": [
                        "InstanceType",
                        "EC2VPC",
                        "EC2Subnet",
                        "EC2KeyName",
                        "SSHLocation",
                        "DatabaseInstanceType",
                        "DatabaseName",
                        "DatabaseUsername",
                        "DatabasePassword",
                        "MultiAZDatabase",
                        "DBAllocatedStorage",
                        "DatabaseSubnets",
                        "DatabaseBackupRetentionPeriod",
                        "DBSnapshotIdentifier"
                    ]
                },
                {
                    "Label": {
                        "default": " [   4Insights   ]   S3  (Data Lake)"
                    },
                    "Parameters": [
                        "DataLakeBucketName",
                        "AthenaDatabaseName"
                    ]
                },
                {
                    "Label": {
                        "default": " [   4Insights   ]   S3 / Redshift Configuration (Data Warehouse)"
                    },
                    "Parameters": [
                        "DataWarehouseBucketName",
                        "RedshiftDatabaseName",
                        "RedshiftDatabaseUsername",
                        "RedshiftDatabasePassword",
                        "RedshiftNodeType",
                        "RedshiftClusterType",
                        "RedshiftNumberOfNodes",
                        "RedshiftPubliclyAccessible",
                        "RedshiftSubnets"
                    ]
                },
                {
                    "Label": {
                        "default": " [   4Insights  ]   Application Configuration"
                    },
                    "Parameters": [
                        "AppCustomerName",
                        "AppAdminPassword"
                    ]
                }
            ],
            "ParameterLabels": {
                "InstanceType": {
                    "default": "EC2 | Instance Type"
                },
                "EC2Subnet": {
                    "default": "EC2 | Subnet"
                },
                "EC2VPC": {
                    "default": "EC2 | VPC"
                },
                "DatabaseInstanceType": {
                    "default": "RDS | Instance Type"
                },
                "DatabaseName": {
                    "default": "RDS | DBName"
                },
                "DatabaseUsername": {
                    "default": "RDS | Username"
                },
                "DatabasePassword": {
                    "default": "RDS | Password"
                },
                "MultiAZDatabase": {
                    "default": "RDS | Multi-AZ"
                },
                "DBAllocatedStorage": {
                    "default": "RDS | Size (GB)"
                },
                "DatabaseBackupRetentionPeriod": {
                    "default": "RDS | Backup Retention"
                },
                "DatabaseSubnets": {
                    "default": "RDS | Private Subnets (min. of 2)"
                },
                "DBSnapshotIdentifier": {
                    "default": "RDS | Snapshot (restore)"
                },
                "DataWarehouseBucketName": {
                    "default": "S3 | Bucket Name"
                },
                "AppCustomerName": {
                    "default": "Application | Customer Name"
                },
                "EC2KeyName": {
                    "default": "EC2 | Key Pair"
                },
                "SSHLocation": {
                    "default": "EC2 | SSH Location"
                },
                "RedshiftDatabaseName": {
                    "default": "Redshift | Database Name"
                },
                "RedshiftDatabaseUsername": {
                    "default": "Redshift | Master user name"
                },
                "RedshiftDatabasePassword": {
                    "default": "Redshift | Master user password"
                },
                "RedshiftNodeType": {
                    "default": "Redshift | Node Type"
                },
                "RedshiftClusterType": {
                    "default": "Redshift | Cluster Type"
                },
                "RedshiftNumberOfNodes": {
                    "default": "Redshift | Number of compute nodes"
                },
                "RedshiftSubnets": {
                    "default": "Redshift | Subnets"
                },
                "AppAdminPassword": {
                    "default": "Application | Admin account password"
                },
                "DataLakeBucketName": {
                    "default": "S3 | Bucket Name"
                },
                "AthenaDatabaseName": {
                    "default": "Athena | Database Name"
                },
                "RedshiftPubliclyAccessible": {
                    "default": "Redshift | Publicly Accessible"
                }
            }
        }
    },
    "Resources": {
        "4InsightsConsoleInstance": {
            "Type": "AWS::EC2::Instance",
            "Metadata": {
                "AWS::CloudFormation::Init": {
                    "configSets": {
                        "InstallAndRun": [
                            "Install"
                        ]
                    },
                    "Install": {
                        "files": {
                            "/etc/cfn/cfn-hup.conf": {
                                "content": {
                                    "Fn::Join": [
                                        "",
                                        [
                                            "[main]\n",
                                            "stack=",
                                            {
                                                "Ref": "AWS::StackId"
                                            },
                                            "\n",
                                            "region=",
                                            {
                                                "Ref": "AWS::Region"
                                            },
                                            "\n"
                                        ]
                                    ]
                                },
                                "mode": "000400",
                                "owner": "root",
                                "group": "root"
                            },
                            "/usr/share/tomcat8/conf/tomcat-users.xml": {
                                "content": {
                                    "Fn::Join": [
                                        "",
                                        [
                                            "<?xml version='1.0' encoding='utf-8'?>\n",
                                            "<tomcat-users xmlns=\"http://tomcat.apache.org/xml\"\n",
                                            "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n",
                                            "xsi:schemaLocation=\"http://tomcat.apache.org/xml tomcat-users.xsd\"\n",
                                            "version=\"1.0\">\n",
                                            "<role rolename=\"manager-gui\"/>\n",
                                            "<role rolename=\"admin-gui\"/>\n",
                                            "<role rolename=\"manager-script\"/> \n",
                                            "<role rolename=\"admin\"/> \n",
                                            "<user username=\"tomcat\" password=\"",
                                            {
                                                "Ref": "AppAdminPassword"
                                            },
                                            "\" roles=\"manager-gui,admin,admin-gui,manager-script\"/>\n",
                                            "</tomcat-users>\n"
                                        ]
                                    ]
                                },
                                "mode": "000664",
                                "owner": "tomcat",
                                "group": "tomcat"
                            },
                            "/usr/share/tomcat8/conf/context.xml": {
                                "content": {
                                    "Fn::Join": [
                                        "",
                                        [
                                            "<?xml version='1.0' encoding='utf-8'?>\n",
                                            "<Context>\n",
                                            "    <WatchedResource>WEB-INF/web.xml</WatchedResource>\n",
                                            "    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>\n",
                                            "    <ResourceLink name=\"jdbc/4InsightsConsoleDB\" global=\"jdbc/4InsightsConsoleDB\"\n",
                                            "                  auth=\"Container\" type=\"javax.sql.DataSource\" />\n",
                                            "    <ResourceLink name=\"url/4InsightsAPI\" global=\"url/4InsightsAPI\"\n",
                                            "                  auth=\"Container\" type=\"java.lang.String\" />\n",
                                            "    <ResourceLink name=\"url/4InsightsAuthorizationServer\" \n",
                                            "                  global=\"url/4InsightsAuthorizationServer\" auth=\"Container\" type=\"java.lang.String\" />\n",
                                            "    <ResourceLink name=\"keys/4InsightsOAuthSigningKey\" \n",
                                            "                  global=\"keys/4InsightsOAuthSigningKey\" auth=\"Container\" type=\"java.lang.String\" />\n",
                                            "</Context>\n"
                                        ]
                                    ]
                                },
                                "mode": "000664",
                                "owner": "tomcat",
                                "group": "tomcat"
                            },
                            "/usr/share/tomcat8/conf/server.xml": {
                                "content": {
                                    "Fn::Join": [
                                        "",
                                        [
                                            "<?xml version='1.0' encoding='utf-8'?>\n",
                                            "<Server port=\"8005\" shutdown=\"SHUTDOWN\">\n",
                                            "     <Listener className=\"org.apache.catalina.startup.VersionLoggerListener\" />\n",
                                            "     <Listener className=\"org.apache.catalina.core.AprLifecycleListener\" SSLEngine=\"on\" />\n",
                                            "     <Listener className=\"org.apache.catalina.core.JreMemoryLeakPreventionListener\" />\n",
                                            "     <Listener className=\"org.apache.catalina.mbeans.GlobalResourcesLifecycleListener\" />\n",
                                            "     <Listener className=\"org.apache.catalina.core.ThreadLocalLeakPreventionListener\" />\n",
                                            "     <GlobalNamingResources>\n",
                                            "         <Resource name=\"UserDatabase\" auth=\"Container\"\n",
                                            "                    type=\"org.apache.catalina.UserDatabase\"\n",
                                            "                    description=\"User database that can be updated and saved\"\n",
                                            "                    factory=\"org.apache.catalina.users.MemoryUserDatabaseFactory\"\n",
                                            "                    pathname=\"conf/tomcat-users.xml\" />\n",
                                            "         <Resource auth=\"Container\" driverClassName=\"com.mysql.jdbc.Driver\"\n",
                                            "                   factory=\"org.apache.tomcat.jdbc.pool.DataSourceFactory\"\n",
                                            "                   jdbcInterceptors=\"org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer\"\n",
                                            "                   logAbandoned=\"true\" maxActive=\"15\" maxIdle=\"10\"\n",
                                            "                   minEvictableIdleTimeMillis=\"30000\" minIdle=\"5\" name=\"jdbc/4InsightsConsoleDB\"\n",
                                            "                   removeAbandoned=\"false\" validationQuery=\"SELECT 1\" removeAbandonedTimeout=\"60\"\n",
                                            "                   password=\"",
                                            {
                                                "Ref": "DatabasePassword"
                                            },
                                            "\"",
                                            "                   testOnBorrow=\"true\" testOnReturn=\"false\" testWhileIdle=\"true\"\n",
                                            "                   timeBetweenEvictionRunsMillis=\"30000\" type=\"javax.sql.DataSource\"\n",
                                            "                   url=\"jdbc:mysql://",
                                            {
                                                "Fn::GetAtt": [
                                                    "4InsightsRDSPrimaryInstance",
                                                    "Endpoint.Address"
                                                ]
                                            },
                                            ":",
                                            {
                                                "Fn::GetAtt": [
                                                    "4InsightsRDSPrimaryInstance",
                                                    "Endpoint.Port"
                                                ]
                                            },
                                            "/",
                                            {
                                                "Ref": "DatabaseName"
                                            },
                                            "\" username=\"",
                                            {
                                                "Ref": "DatabaseUsername"
                                            },
                                            "\" />\n",
                                            "          <Environment auth=\"Container\" name=\"url/4InsightsAPI\" type=\"java.lang.String\" value=\"http://localhost:8080/\" />\n",
                                            "          <Environment auth=\"Container\" name=\"url/4InsightsAuthorizationServer\" type=\"java.lang.String\" value=\"http://localhost:8080/\" />\n",
                                            "          <Environment auth=\"Container\" name=\"keys/4InsightsOAuthSigningKey\" type=\"java.lang.String\" value=\"InstanceIdChangeMe\" />",
                                            "    </GlobalNamingResources>\n",
                                            "    <Service name=\"Catalina\">\n",
                                            "          <Connector port=\"8080\" protocol=\"HTTP/1.1\"\n",
                                            "                     connectionTimeout=\"20000\"\n",
                                            "                     redirectPort=\"8443\" />\n",
                                            "          <Connector port=\"8009\" protocol=\"AJP/1.3\" redirectPort=\"8443\" />\n",
                                            "          <Engine name=\"Catalina\" defaultHost=\"localhost\">\n",
                                            "                <Realm className=\"org.apache.catalina.realm.LockOutRealm\">\n",
                                            "                       <Realm className=\"org.apache.catalina.realm.UserDatabaseRealm\"\n",
                                            "                              resourceName=\"UserDatabase\"/>\n",
                                            "                </Realm>\n",
                                            "                <Host name=\"localhost\"  appBase=\"webapps\"\n",
                                            "                      unpackWARs=\"true\" autoDeploy=\"true\">\n",
                                            "                            <Valve className=\"org.apache.catalina.valves.AccessLogValve\" directory=\"logs\"\n",
                                            "                                   prefix=\"localhost_access_log\" suffix=\".txt\"\n",
                                            "                                   pattern=\"%h %l %u %t &quot;%r&quot; %s %b\" />\n",
                                            "                </Host>\n",
                                            "          </Engine>\n",
                                            "    </Service>\n",
                                            "</Server>\n"
                                        ]
                                    ]
                                },
                                "mode": "000664",
                                "owner": "tomcat",
                                "group": "tomcat"
                            },
                            "/tmp/4insights/bootstrap-conf.properties": {
                                "content": {
                                    "Fn::Join": [
                                        "",
                                        [
                                            "bootstrap.metadata.url=jdbc:mysql://",
                                            {
                                                "Fn::GetAtt": [
                                                    "4InsightsRDSPrimaryInstance",
                                                    "Endpoint.Address"
                                                ]
                                            },
                                            ":",
                                            {
                                                "Fn::GetAtt": [
                                                    "4InsightsRDSPrimaryInstance",
                                                    "Endpoint.Port"
                                                ]
                                            },
                                            "/",
                                            {
                                                "Ref": "DatabaseName"
                                            },
                                            "\n",
                                            "bootstrap.metadata.user=",
                                            {
                                                "Ref": "DatabaseUsername"
                                            },
                                            "\n",
                                            "bootstrap.metadata.password=",
                                            {
                                                "Ref": "DatabasePassword"
                                            },
                                            "\n",
                                            "bootstrap.metadata.driver=com.mysql.jdbc.Driver\n",
                                            "bootstrap.metadata.dialect=org.hibernate.dialect.MySQLDialect\n",
                                            "bootstrap.customer=",
                                            {
                                                "Ref": "AppCustomerName"
                                            },
                                            "\n",
                                            "bootstrap.user.password=",
                                            {
                                                "Ref": "AppAdminPassword"
                                            },
                                            "\n",
                                            "bootstrap.smtp.server=smtp.company.com\n",
                                            "bootstrap.smtp.port=587\n",
                                            "bootstrap.smtp.email=noreply@yourcompany.com.br\n",
                                            "bootstrap.smtp.password=123456\n",
                                            "bootstrap.smtp.tls=true\n",
                                            "bootstrap.smtp.auth=true\n",
                                            "bootstrap.environment=DEV\n",
                                            "bootstrap.environment.loader=http://ChangeMe\n",
                                            "bootstrap.environment.log.path=/logs\n",
                                            "bootstrap.environment.database.id=2\n",
                                            "bootstrap.environment.database.host=",
                                            {
                                                "Fn::GetAtt": [
                                                    "4InsightsRedshiftDataWarehouse",
                                                    "Endpoint.Address"
                                                ]
                                            },
                                            "\n",
                                            "bootstrap.environment.database.port=5439\n",
                                            "bootstrap.environment.database.schema=",
                                            {
                                                "Ref": "RedshiftDatabaseName"
                                            },
                                            "\n",
                                            "bootstrap.environment.database.user=",
                                            {
                                                "Ref": "RedshiftDatabaseUsername"
                                            },
                                            "\n",
                                            "bootstrap.environment.database.password=",
                                            {
                                                "Ref": "RedshiftDatabasePassword"
                                            },
                                            "\n",
                                            "bootstrap.environment.s3.region=",
                                            {
                                                "Ref": "AWS::Region"
                                            },
                                            "\n",
                                            "bootstrap.environment.s3.bucket=",
                                            {
                                                "Ref": "DataWarehouseBucketName"
                                            },
                                            "\n",
                                            "bootstrap.environment.s3.accesskey=",
                                            {
                                                "Ref": "4InsightAccessKey"
                                            },
                                            "\n",
                                            "bootstrap.environment.s3.secretkey=",
                                            {
                                                "Fn::GetAtt": [
                                                    "4InsightAccessKey",
                                                    "SecretAccessKey"
                                                ]
                                            },
                                            "\n",
                                            "bootstrap.environment.datalake=DEV\n",
                                            "bootstrap.environment.datalake.loader=http://ChangeMe\n",
                                            "bootstrap.environment.datalake.catalog.id=4\n",
                                            "bootstrap.environment.datalake.catalog.host=\"AwsRegion=",
                                            {
                                                "Ref": "AWS::Region"
                                            },
                                            ";S3OutputLocation=s3://",
                                            {
                                                "Ref": "DataLakeBucketName"
                                            },
                                            "/tmp\"",
                                            "\n",
                                            "bootstrap.environment.datalake.catalog.port=443\n",
                                            "bootstrap.environment.datalake.catalog.database=",
                                            {
                                                "Ref": "AthenaDatabaseName"
                                            },
                                            "\n",
                                            "bootstrap.environment.datalake.catalog.user=",
                                            {
                                                "Ref": "4InsightAccessKey"
                                            },
                                            "\n",
                                            "bootstrap.environment.datalake.catalog.password=",
                                            {
                                                "Fn::GetAtt": [
                                                    "4InsightAccessKey",
                                                    "SecretAccessKey"
                                                ]
                                            },
                                            "\n",
                                            "bootstrap.environment.datalake.s3.region=",
                                            {
                                                "Ref": "AWS::Region"
                                            },
                                            "\n",
                                            "bootstrap.environment.datalake.s3.bucket=",
                                            {
                                                "Ref": "DataLakeBucketName"
                                            },
                                            "\n",
                                            "bootstrap.environment.datalake.s3.accesskey=",
                                            {
                                                "Ref": "4InsightAccessKey"
                                            },
                                            "\n",
                                            "bootstrap.environment.datalake.s3.secretkey=",
                                            {
                                                "Fn::GetAtt": [
                                                    "4InsightAccessKey",
                                                    "SecretAccessKey"
                                                ]
                                            },
                                            "\n"
                                        ]
                                    ]
                                },
                                "mode": "000777",
                                "owner": "tomcat",
                                "group": "tomcat"
                            },
                            "/etc/cfn/hooks.d/cfn-auto-reloader.conf": {
                                "content": {
                                    "Fn::Join": [
                                        "",
                                        [
                                            "[cfn-auto-reloader-hook]\n",
                                            "triggers=post.update\n",
                                            "path=Resources.4InsightsConsoleInstance.Metadata.AWS::CloudFormation::Init\n",
                                            "action=/opt/aws/bin/cfn-init -v ",
                                            "         --stack ",
                                            {
                                                "Ref": "AWS::StackName"
                                            },
                                            "         --resource 4InsightsConsoleInstance ",
                                            "         --configsets InstallAndRun ",
                                            "         --region ",
                                            {
                                                "Ref": "AWS::Region"
                                            },
                                            "\n",
                                            "runas=root\n"
                                        ]
                                    ]
                                }
                            }
                        },
                        "services": {
                            "sysvinit": {
                                "cfn-hup": {
                                    "enabled": "true",
                                    "ensureRunning": "true",
                                    "files": [
                                        "/etc/cfn/cfn-hup.conf",
                                        "/etc/cfn/hooks.d/cfn-auto-reloader.conf"
                                    ]
                                },
                                "tomcat8": {
                                    "enabled": "true",
                                    "ensureRunning": "true",
                                    "files": [
                                        "/etc/tomcat8/tomcat8.conf"
                                    ]
                                }
                            }
                        }
                    }
                }
            },
            "Properties": {
                "ImageId": {
                    "Fn::FindInMap": ["AWSRegionArch2AMI", {
                            "Ref": "AWS::Region"
                        },
                        {
                            "Fn::FindInMap": ["AWSInstanceType2Arch", {
                                "Ref": "InstanceType"
                            }, "Arch"]
                        }
                    ]
                },
                "InstanceType": {
                    "Ref": "InstanceType"
                },
                "Tags": [{
                    "Key": "Name",
                    "Value": "4Insights"
                }],
                "KeyName": {
                    "Ref": "EC2KeyName"
                },
                "NetworkInterfaces": [{
                    "AssociatePublicIpAddress": "True",
                    "DeleteOnTermination": "True",
                    "SubnetId": {
                        "Fn::Join": [
                            "",
                            {
                                "Ref": "EC2Subnet"
                            }
                        ]
                    },
                    "DeviceIndex": "0",
                    "GroupSet": [{
                        "Ref": "4InsightsConsoleSecurityGroup"
                    }]
                }],
                "UserData": {
                    "Fn::Base64": {
                        "Fn::Join": [
                            "",
                            [
                                "#!/bin/bash -xe\n",
                                "yum update -y aws-cfn-bootstrap\n",
                                "yum install java-1.8.0 -y\n",
                                "yum remove java-1.7.0-openjdk -y\n",
                                "yum install tomcat8 tomcat8-webapps -y\n",
                                "chown -R tomcat /usr/share/tomcat8/\n",
                                "chown -R tomcat /var/lib/tomcat8\n",
                                "chkconfig --level 345 tomcat8 on\n",
                                "/sbin/iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080\n",
                                "/sbin/service iptables save\n",
                                "mkdir /logs\n",
                                "chmod 777 /logs\n",
                                "cp /usr/share/tomcat8/conf/tomcat-users.xml /usr/share/tomcat8/conf/tomcat-users.old\n",
                                "cp /usr/share/tomcat8/conf/context.xml /usr/share/tomcat8/conf/context.old\n",
                                "cp /usr/share/tomcat8/conf/server.xml /usr/share/tomcat8/conf/server.old\n",
                                "# Install the files and packages from the metadata\n",
                                "/opt/aws/bin/cfn-init -v ",
                                "         --stack ",
                                {
                                    "Ref": "AWS::StackName"
                                },
                                "         --resource 4InsightsConsoleInstance ",
                                "         --configsets InstallAndRun ",
                                "         --region ",
                                {
                                    "Ref": "AWS::Region"
                                },
                                "\n",
                                "cd /tmp/4insights\n",
                                "change=`curl http://169.254.169.254/latest/meta-data/public-ipv4/`\n",
                                "instanceIdChange=`curl http://169.254.169.254/latest/meta-data/instance-id/`\n",
                                "sed -e \"s|ChangeMe|$change|g\" /tmp/4insights/bootstrap-conf.properties -i \n",
                                "sed -e \"s|ChangeMe|$change|g\" /usr/share/tomcat8/conf/server.xml -i \n",
                                "sed -e \"s|InstanceIdChangeMe|$instanceIdChange|g\" /usr/share/tomcat8/conf/server.xml -i \n",
                                "wget https://4insights-packages.s3.amazonaws.com/public/latest/4insights.war\n",
                                "wget https://4insights-packages.s3.amazonaws.com/public/latest/4insights-authentication.war\n",
                                "wget https://4insights-packages.s3.amazonaws.com/public/latest/4insights-loader.war\n",
                                "wget https://4insights-packages.s3.amazonaws.com/public/latest/console.war\n",
                                "wget https://4insights-packages.s3.amazonaws.com/public/latest/4insights-bootstrap.jar\n",
                                "service tomcat8 stop\n",
                                "/usr/bin/java -jar 4insights-bootstrap.jar --file-config=\"/tmp/4insights/bootstrap-conf.properties\"\n",
                                "mv 4insights.war /usr/share/tomcat8/webapps/4insights.war\n",
                                "mv 4insights-loader.war /usr/share/tomcat8/webapps/4insights-loader.war\n",
                                "mv 4insights-authentication.war /usr/share/tomcat8/webapps/4insights-authentication.war\n",
                                "rm -rf /usr/share/tomcat8/webapps/ROOT\n",
                                "mv console.war /usr/share/tomcat8/webapps/ROOT.war\n",
                                "rm -rf 4insights-bootstrap.jar bootstrap-conf.properties\n",
                                "service tomcat8 start\n"
                            ]
                        ]
                    }
                }
            },
            "DependsOn": [
                "4InsightsRDSPrimaryInstance",
                "4InsightsRedshiftDataWarehouse"
            ]
        },
        "4InsightsConsoleSecurityGroup": {
            "Type": "AWS::EC2::SecurityGroup",
            "Properties": {
                "VpcId": {
                    "Ref": "EC2VPC"
                },
                "GroupDescription": "Enable HTTP(S)/SSH access in VPC",
                "SecurityGroupIngress": [{
                        "IpProtocol": "tcp",
                        "FromPort": "80",
                        "ToPort": "80",
                        "CidrIp": "0.0.0.0/0"
                    },
                    {
                        "IpProtocol": "tcp",
                        "FromPort": "22",
                        "ToPort": "22",
                        "CidrIp": {
                            "Ref": "SSHLocation"
                        }
                    },
                    {
                        "IpProtocol": "tcp",
                        "FromPort": "443",
                        "ToPort": "443",
                        "CidrIp": "0.0.0.0/0"
                    }
                ]
            }
        },
        "4InsightsRDSDBParameterGroup": {
            "Type": "AWS::RDS::DBParameterGroup",
            "Properties": {
                "Description": "Custom parameter group for 4insights",
                "Family": "mysql5.6",
                "Parameters": {
                    "event_scheduler": "OFF",
                    "max_allowed_packet": "16777216"
                }
            }
        },
        "4InsightsRDSSecurityGroup": {
            "Type": "AWS::EC2::SecurityGroup",
            "Properties": {
                "VpcId": {
                    "Ref": "EC2VPC"
                },
                "GroupDescription": "Enable access to RDS",
                "SecurityGroupIngress": [{
                    "IpProtocol": "tcp",
                    "FromPort": "3306",
                    "ToPort": "3306",
                    "SourceSecurityGroupId": {
                        "Fn::GetAtt": [
                            "4InsightsConsoleSecurityGroup",
                            "GroupId"
                        ]
                    }
                }]
            }
        },
        "4InsightsRedshiftSecurityGroup": {
            "Type": "AWS::EC2::SecurityGroup",
            "Properties": {
                "VpcId": {
                    "Ref": "EC2VPC"
                },
                "GroupDescription": "Enable access to Redshift",
                "SecurityGroupIngress": [{
                    "IpProtocol": "tcp",
                    "FromPort": "5439",
                    "ToPort": "5439",
                    "SourceSecurityGroupId": {
                        "Fn::GetAtt": [
                            "4InsightsConsoleSecurityGroup",
                            "GroupId"
                        ]
                    }
                }]
            }
        },
        "4InsightsS3DataWarehouseBucket": {
            "Type": "AWS::S3::Bucket",
            "Properties": {
                "AccessControl": "Private",
                "BucketName": {
                    "Ref": "DataWarehouseBucketName"
                },
                "Tags": [{
                    "Key": "Name",
                    "Value": "4Insights"
                }]
            }
        },
        "4InsightsS3DataLakeBucket": {
            "Type": "AWS::S3::Bucket",
            "Properties": {
                "AccessControl": "Private",
                "BucketName": {
                    "Ref": "DataLakeBucketName"
                },
                "Tags": [{
                    "Key": "Name",
                    "Value": "4Insights"
                }]
            }
        },
        "4InsightsUser": {
            "Type": "AWS::IAM::User",
            "Properties": {
                "Path": "/",
                "LoginProfile": {
                    "Password": {
                        "Ref": "DatabasePassword"
                    }
                },
                "Policies": [{
                    "PolicyName": "AthenaAccessPolicy",
                    "PolicyDocument": {
                        "Version": "2012-10-17",
                        "Statement": [{
                            "Effect": "Allow",
                            "Action": "athena:*",
                            "Resource": "*"
                        }]
                    }
                },{
                    "PolicyName": "GlueAccessPolicy",
                    "PolicyDocument": {
                        "Version": "2012-10-17",
                        "Statement": [{
                            "Effect": "Allow",
                            "Action": "glue:*",
                            "Resource": "*"
                        }]
                    }
                },
				{
                    "PolicyName": "S3AccessOnlyPolicy",
                    "PolicyDocument": {
                        "Version": "2012-10-17",
                        "Statement": [{
                            "Effect": "Allow",
                            "Action": "s3:*",
                            "Resource": [{
                                    "Fn::Join": [
                                        "",
                                        [
                                            "arn:aws:s3:::",
                                            {
                                                "Ref": "DataWarehouseBucketName"
                                            }
                                        ]
                                    ]
                                },
                                {
                                    "Fn::Join": [
                                        "",
                                        [
                                            "arn:aws:s3:::",
                                            {
                                                "Ref": "DataWarehouseBucketName"
                                            },
                                            "/*"
                                        ]
                                    ]
                                },
                                {
                                    "Fn::Join": [
                                        "",
                                        [
                                            "arn:aws:s3:::",
                                            {
                                                "Ref": "DataLakeBucketName"
                                            }
                                        ]
                                    ]
                                },
                                {
                                    "Fn::Join": [
                                        "",
                                        [
                                            "arn:aws:s3:::",
                                            {
                                                "Ref": "DataLakeBucketName"
                                            },
                                            "/*"
                                        ]
                                    ]
                                }
                            ]
                        }]
                    }
                }]
            }
        },
        "4InsightAccessKey": {
            "Type": "AWS::IAM::AccessKey",
            "Properties": {
                "UserName": {
                    "Ref": "4InsightsUser"
                }
            }
        },
        "4InsightsStackAlarmTopic": {
            "Type": "AWS::SNS::Topic",
            "Properties": {
                "DisplayName": "Stack Alarm Topic"
            }
        },
        "4InsightsRDSDBSubnetGroup": {
            "Type": "AWS::RDS::DBSubnetGroup",
            "Properties": {
                "DBSubnetGroupDescription": "CloudFormation managed DB subnet group.",
                "SubnetIds": {
                    "Ref": "DatabaseSubnets"
                }
            }
        },
        "4InsightsRDSPrimaryInstance": {
            "Type": "AWS::RDS::DBInstance",
            "Properties": {
                "DBName": {
                    "Fn::If": [
                        "UseDbSnapshot",
                        {
                            "Ref": "AWS::NoValue"
                        },
                        {
                            "Ref": "DatabaseName"
                        }
                    ]
                },
                "MasterUsername": {
                    "Ref": "DatabaseUsername"
                },
                "MasterUserPassword": {
                    "Ref": "DatabasePassword"
                },
                "Engine": "MySQL",
                "EngineVersion": "5.6.34",
                "AllocatedStorage": {
                    "Ref": "DBAllocatedStorage"
                },
                "BackupRetentionPeriod": {
                    "Ref": "DatabaseBackupRetentionPeriod"
                },
                "DBInstanceClass": {
                    "Ref": "DatabaseInstanceType"
                },
                "DBSubnetGroupName": {
                    "Ref": "4InsightsRDSDBSubnetGroup"
                },
                "MultiAZ": {
                    "Ref": "MultiAZDatabase"
                },
                "DBSnapshotIdentifier": {
                    "Fn::If": [
                        "UseDbSnapshot",
                        {
                            "Ref": "DBSnapshotIdentifier"
                        },
                        {
                            "Ref": "AWS::NoValue"
                        }
                    ]
                },
                "DBParameterGroupName": {
                    "Ref": "4InsightsRDSDBParameterGroup"
                },
                "VPCSecurityGroups": [{
                    "Fn::GetAtt": [
                        "4InsightsRDSSecurityGroup",
                        "GroupId"
                    ]
                }]
            },
            "DeletionPolicy": "Snapshot"
        },
        "4InsightsRDSPrimaryCPUAlarm": {
            "Type": "AWS::CloudWatch::Alarm",
            "Properties": {
                "AlarmDescription": "Primary database CPU utilization is over 90%.",
                "Namespace": "AWS/RDS",
                "MetricName": "CPUUtilization",
                "Unit": "Percent",
                "Statistic": "Average",
                "Period": 300,
                "EvaluationPeriods": 2,
                "Threshold": 90,
                "ComparisonOperator": "GreaterThanOrEqualToThreshold",
                "Dimensions": [{
                    "Name": "DBInstanceIdentifier",
                    "Value": {
                        "Ref": "4InsightsRDSPrimaryInstance"
                    }
                }],
                "AlarmActions": [{
                    "Ref": "4InsightsStackAlarmTopic"
                }],
                "InsufficientDataActions": [{
                    "Ref": "4InsightsStackAlarmTopic"
                }]
            }
        },
        "4InsightsRDSPrimaryMemoryAlarm": {
            "Type": "AWS::CloudWatch::Alarm",
            "Properties": {
                "AlarmDescription": "Database freeable memory is under 300MB.",
                "Namespace": "AWS/RDS",
                "MetricName": "FreeableMemory",
                "Unit": "Bytes",
                "Statistic": "Average",
                "Period": 300,
                "EvaluationPeriods": 2,
                "Threshold": 300000000,
                "ComparisonOperator": "LessThanOrEqualToThreshold",
                "Dimensions": [{
                    "Name": "DBInstanceIdentifier",
                    "Value": {
                        "Ref": "4InsightsRDSPrimaryInstance"
                    }
                }],
                "AlarmActions": [{
                    "Ref": "4InsightsStackAlarmTopic"
                }],
                "InsufficientDataActions": [{
                    "Ref": "4InsightsStackAlarmTopic"
                }]
            }
        },
        "4InsightsRedshiftDiskAlarm": {
            "Type": "AWS::CloudWatch::Alarm",
            "Properties": {
                "AlarmDescription": "Threshold at which the alarm will trigger when disk usage across all nodes reaches 80%.",
                "Namespace": "AWS/Redshift",
                "MetricName": "PercentageDiskSpaceUsed",
                "Unit": "Percent",
                "Statistic": "Average",
                "Period": 300,
                "EvaluationPeriods": 2,
                "Threshold": 80,
                "ComparisonOperator": "GreaterThanOrEqualToThreshold",
                "Dimensions": [{
                    "Name": "ClusterIdentifier",
                    "Value": {
                        "Ref": "4InsightsRedshiftDataWarehouse"
                    }
                }],
                "AlarmActions": [{
                    "Ref": "4InsightsStackAlarmTopic"
                }],
                "InsufficientDataActions": [{
                    "Ref": "4InsightsStackAlarmTopic"
                }]
            }
        },
        "4InsightsRedshiftSpectrumRole": {
            "Type": "AWS::IAM::Role",
            "Properties": {
                "AssumeRolePolicyDocument": {
                    "Statement": [{
                        "Effect": "Allow",
                        "Principal": {
                            "Service": [
                                "redshift.amazonaws.com"
                            ]
                        },
                        "Action": [
                            "sts:AssumeRole"
                        ]
                    }]
                },
                "Path": "/",
                "Policies": [{
                    "PolicyName": "4InsightsRedshiftSpectrumPolicy",
                    "PolicyDocument": {
                        "Version": "2012-10-17",
                        "Statement": [{
                            "Effect": "Allow",
                            "Action": [
                                "s3:Get*",
                                "s3:List*",
                                "athena:*"
                            ],
                            "Resource": [{
                                "Fn::Join": [
                                    "",
                                    [
                                        "arn:aws:s3:::",
                                        {
                                            "Ref": "DataLakeBucketName"
                                        },
                                        "/*"
                                    ]
                                ]
                            }]
                        }]
                    }
                }]
            }
        },
        "4InsightsRedshiftDataWarehouse": {
            "Type": "AWS::Redshift::Cluster",
            "DependsOn": [
                "4InsightsRedshiftSpectrumRole"
            ],
            "Properties": {
                "DBName": {
                    "Ref": "RedshiftDatabaseName"
                },
                "MasterUsername": {
                    "Ref": "RedshiftDatabaseUsername"
                },
                "MasterUserPassword": {
                    "Ref": "RedshiftDatabasePassword"
                },
                "NodeType": {
                    "Ref": "RedshiftNodeType"
                },
                "ClusterType": {
                    "Ref": "RedshiftClusterType"
                },
                "NumberOfNodes": {
                    "Fn::If": [
                        "UseRedshiftNumberOfNodes",
                        {
                            "Ref": "RedshiftNumberOfNodes"
                        },
                        {
                            "Ref": "AWS::NoValue"
                        }
                    ]
                },
                "ClusterSubnetGroupName": {
                    "Ref": "4InsightsRedshiftClusterSubnetGroup"
                },
                "VpcSecurityGroupIds": [{
                    "Fn::GetAtt": [
                        "4InsightsRedshiftSecurityGroup",
                        "GroupId"
                    ]
                }],
                "IamRoles": [{
                    "Fn::GetAtt": [
                        "4InsightsRedshiftSpectrumRole",
                        "Arn"
                    ]
                }],
                "PubliclyAccessible": false
            }
        },
        "4InsightsRedshiftClusterSubnetGroup": {
            "Type": "AWS::Redshift::ClusterSubnetGroup",
            "Properties": {
                "Description": "The cluster subnet group for redshift",
                "SubnetIds": {
                    "Ref": "RedshiftSubnets"
                }
            }
        },
        "4InsightsGlueDatabase": {
            "Type": "AWS::Glue::Database",
            "Properties": {
                "DatabaseInput": {
                    "Name": {
                        "Ref": "AthenaDatabaseName"
                    },
                    "Description": "Database for datalake tables"
                },
                "CatalogId": {
                    "Ref": "AWS::AccountId"
                }
            }
        }
    },
    "Outputs": {
        "4InsightsConsoleURL": {
            "Description": "URL for newly created Apache server",
            "Value": {
                "Fn::Join": [
                    "",
                    [
                        "http://",
                        {
                            "Fn::GetAtt": [
                                "4InsightsConsoleInstance",
                                "PublicDnsName"
                            ]
                        }
                    ]
                ]
            }
        },
        "UserS3AccessKey": {
            "Description": "Access Key used by 4Insights",
            "Value": {
                "Ref": "4InsightAccessKey"
            }
        },
        "UserS3SecretKey": {
            "Description": "Secret Key used by 4Insights",
            "Value": {
                "Fn::GetAtt": [
                    "4InsightAccessKey",
                    "SecretAccessKey"
                ]
            }
        }
    }
}