{
  "AWSTemplateFormatVersion" : "2010-09-09",
  "Description" : "ArcGIS CloudFormation Template: Provisions an ArcGIS for Server site on EC2 instances running Ubuntu LTS 16.04. **WARNING** You will be billed by AWS for the AWS resources if you create a stack from this template.",
  "Mappings" : {
    "RegionMap" : {
      "ap-northeast-1": {
        "en": "ami-0b8bf3ce6f2a7d076"
      },
      "ap-northeast-2": {
        "en": "ami-040db4ef8af186851"
      },
      "ap-south-1": {
        "en": "ami-0ff9ca78daa94d2b8"
      },
      "ap-southeast-1": {
        "en": "ami-0df830612a9891a26"
      },
      "ap-southeast-2": {
        "en": "ami-0dc13b196188a0c64"
      },
      "ca-central-1": {
        "en": "ami-02beb5d0affe127f4"
      },
      "eu-central-1": {
        "en": "ami-06b6192897122f6af"
      },
      "eu-west-1": {
        "en": "ami-0650a2f1599c46fa4"
      },
      "eu-west-2": {
        "en": "ami-06a36d7817ceb8332"
      },
      "sa-east-1": {
        "en": "ami-0061b115ec5fccf00"
      },
      "us-east-1": {
        "en": "ami-0a7119f3d82e4fcba"
      },
      "us-east-2": {
        "en": "ami-01c5468810fbef9a5"
      },
      "us-west-1": {
        "en": "ami-06dbf5022dae1f689"
      },
      "us-west-2": {
        "en": "ami-060ed8275ff678a89"
      }
    },
    "DBEngineProperties" : {
      "postgres" : {"MajorVersion": "9.6", "Version": "9.6.20", "License": "postgresql-license"}
    }
  },
  "Parameters" : {
    "DeploymentBucket" : {
      "Description" : "S3 bucket with ArcGIS Server authorization file",
      "Type" : "String",
      "AllowedPattern" : "[a-zA-Z][0-9a-zA-Z-_.]{2,62}",
      "ConstraintDescription" : "S3 bucket name must be between 3 and 63 characters and and must start with a letter."
    },
    "DriveSizeRoot" : {
      "Default" : "100",
      "Description" : "The size of the C: Drive in GB.",
      "Type" : "Number",
      "MinValue" : "100",
      "MaxValue" : "1024",
      "ConstraintDescription" : "Must be between 100 and 1024 GB."
    },
    "DriveSizeData" : {
      "Default" : "100",
      "Description" : "The size of the D: Drive in GB.",
      "Type" : "Number",
      "MinValue" : "10",
      "MaxValue" : "1024",
      "ConstraintDescription" : "Must be between 10 and 1024 GB."
    },
    "FSInstanceType": {
      "Description": "The file server EC2 instance type",
      "Type": "String",
      "AllowedValues": [
        "m3.large", "m3.xlarge", "m3.2xlarge",
        "m4.large", "m4.xlarge", "m4.2xlarge", "m4.4xlarge", "m4.10xlarge",
        "c4.large", "c4.xlarge", "c4.2xlarge", "c4.4xlarge", "c4.8xlarge",
        "c3.large", "c3.xlarge", "c3.2xlarge", "c3.4xlarge", "c3.8xlarge",
        "r3.large", "r3.xlarge", "r3.2xlarge", "r3.4xlarge", "r3.8xlarge"
      ],
      "Default": "m3.large",
      "ConstraintDescription" : "Only C3, C4, M3, and R3 instance types are supported"
    },
    "ASInstanceType": {
      "Description": "The ArcGIS Server EC2 instance type",
        "Type": "String",
        "AllowedValues": [
          "m3.large", "m3.xlarge", "m3.2xlarge",
          "m4.large", "m4.xlarge", "m4.2xlarge", "m4.4xlarge", "m4.10xlarge",
          "c4.large", "c4.xlarge", "c4.2xlarge", "c4.4xlarge", "c4.8xlarge",
          "c3.large", "c3.xlarge", "c3.2xlarge", "c3.4xlarge", "c3.8xlarge",
          "r3.large", "r3.xlarge", "r3.2xlarge", "r3.4xlarge", "r3.8xlarge"
        ],
        "Default": "m3.large"
    },
    "SecondaryInstances" : {
      "Description" : "Number of secondary ArcGIS Server EC2 instances launched by AutoScaling",
      "Type" : "Number",
      "Default" : "1"
    },
    "KeyName" : {
      "Description" : "EC2 Key Pair to allow RemoteDesktop access to the instances",
      "Type" : "AWS::EC2::KeyPair::KeyName"
    },
    "StoreType": {
      "Description": "ArcGIS Server config store type",
      "Type": "String",
      "AllowedValues": ["CloudStore", "FileSystem"],
      "Default": "FileSystem"
    }, 
    "ServerLicenseFile": {
      "Description": "ArcGIS for Server authorization file (must be uploaded to DeploymentBucket)",
      "Type": "String",
      "AllowedPattern": "[^\"]{1,1024}",
      "ConstraintDescription": "S3 object key name must be between 1 and 1024 characters."
    },
    "SiteAdmin" : {
      "Description" : "User name for ArcGIS Server site admin account",
      "Type" : "String",
      "Default" : "admin",
      "AllowedPattern": "[^\\\"]{1,128}",
      "ConstraintDescription": "User name must be between 1 and 128 characters and must not contain backslashes (\\) or quotation marks (\")."
    },
    "SiteAdminPassword" : {
      "Description" : "Password for the site admin account",
      "Type" : "String",
      "NoEcho" : "true",
      "AllowedPattern": "[^\\\"@/]{8,128}",
      "ConstraintDescription": "Password must be between 1 and 128 characters and must not contain slasher (/), backslashes (\\), quotation marks (\"), and at (@)."
    },
    "SSLCertificateFile": {
      "Description": "SSL certificate file issued to the site domain (must be uploaded to DeploymentBucket)",
      "Type": "String",
      "AllowedPattern": "[^\"]{1,1024}",
      "ConstraintDescription": "S3 object key name must be between 1 and 1024 characters."
    },
    "SSLCertPassword": {
      "Description": "SSL certificate file password",
      "Type": "String",
      "NoEcho": "true",
      "AllowedPattern": "[^\\\"]{1,128}",
      "ConstraintDescription": "Password must be between 1 and 128 characters and must not contain backslashes (\\) or quotation marks (\")."
    },
    "DBEngine": {
      "Description": "RDS engine",
      "Type": "String",
      "AllowedValues": ["none", "postgres"],
      "Default": "none"
    },
    "DBInstanceClass": {
        "Description": "The RDS instance class",
        "Type": "String",
        "AllowedValues": [
            "db.m3.medium", "db.m3.large", "db.m3.xlarge", "db.m3.2xlarge",
            "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",
            "db.t2.micro", "db.t2.small", "db.t2.medium", "db.t2.large"
        ],
        "Default": "db.m4.large"
    },
    "DBAllocatedStorage" : {
        "Default" : "200",
        "Description" : "The allocated storage size of RDS instance specified in gigabytes (GB).",
        "Type" : "Number",
        "MinValue" : "200",
        "MaxValue" : "4096",
      "ConstraintDescription" : "Must be between 200 and 4096."
    },
    "VPCId" : {
      "Description" : "VPC ID",
      "Type" : "AWS::EC2::VPC::Id" 
    },
    "Subnet1" : {
      "Description" : "Subnet 1",
      "Type": "AWS::EC2::Subnet::Id"
    },
    "Subnet2" : {
      "Description" : "Subnet 2",
      "Type": "AWS::EC2::Subnet::Id"
    }
  },
  "Metadata" : {
    "AWS::CloudFormation::Interface" : {
      "ParameterGroups" : [ {
        "Label" : { "default" : "Network Configuration" },
        "Parameters" : [ "VPCId", "Subnet1", "Subnet2" ]
      },
      {
        "Label" : { "default":"Amazon EC2 Configuration" },
        "Parameters" : [ "FSInstanceType", "ASInstanceType", "SecondaryInstances", "DriveSizeRoot", "DriveSizeData", "KeyName", "DBEngine", "DBInstanceClass", "DBAllocatedStorage" ]
      },
      {
        "Label" : { "default":"ArcGIS Enterprise Configuration" },
        "Parameters" : [ "DeploymentBucket", "ServerLicenseFile", "StoreType", "SiteAdmin", "SiteAdminPassword", "SSLCertificateFile", "SSLCertPassword" ]
      } ]
    }
  },
  "Conditions" : {
    "CreateDBInstance" : {"Fn::Not" : [{"Fn::Equals" : [{"Ref" : "DBEngine"}, "none"]}]},
    "DBEnginePostgres" : {"Fn::Equals" : [{"Ref" : "DBEngine"}, "postgres"]},
    "CreateDHCPOptions" : {"Fn::Equals" : [{"Ref" : "AWS::Region"}, "us-east-1"]},
    "UseCloudStore" : {"Fn::Equals" : [{"Ref" : "StoreType"}, "CloudStore"]}
  },
  "Resources" : {
    "ValidateParametersFunction": {
      "Type": "AWS::Lambda::Function",
      "DependsOn": "IAMRole",
      "Properties": {
        "Code": {
          "S3Bucket": {"Fn::Join" : ["", ["arcgisstore105", "-", {"Ref": "AWS::Region"}]]},
          "S3Key": "6491/lambda/arcgis-cfn-lambda-python3.zip"
        },
        "Handler": "parameters.handler",
        "Runtime": "python3.8",
        "Timeout": "300",
        "Role": { "Fn::GetAtt" : ["LambdaExecutionRole", "Arn"] }
      }
    },
    "LambdaExecutionRole": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "AssumeRolePolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [{
            "Effect": "Allow",
            "Principal": {"Service": ["lambda.amazonaws.com"]},
            "Action": ["sts:AssumeRole"]
          }]
        },
        "Path": "/",
        "Policies": [{
          "PolicyName": "root",
          "PolicyDocument": {
            "Version": "2012-10-17",
            "Statement": [{
             "Effect": "Allow",
              "Action": ["logs:CreateLogGroup","logs:CreateLogStream","logs:PutLogEvents"],
              "Resource": "arn:aws:logs:*:*:*"
            },
            {
              "Effect": "Allow",
              "Action": ["dynamodb:*"],
              "Resource": "*"
            },
            {
              "Effect": "Allow",
              "Action": ["s3:*"],
              "Resource": "*"
            }]
          }
        }]
      }
    },
    "ValidateServerLicenseFile": {
      "Type": "Custom::ValidateParameters",
      "Properties": {
        "ServiceToken": {"Fn::GetAtt": ["ValidateParametersFunction", "Arn"]},
        "DeploymentBucket": {"Ref": "DeploymentBucket"},
        "S3Key": {"Ref": "ServerLicenseFile"}
      }
    },
    "ValidateSSLCertificateFile": {
      "Type": "Custom::ValidateParameters",
      "DependsOn": "ValidateServerLicenseFile",
      "Properties": {
        "ServiceToken": {"Fn::GetAtt": ["ValidateParametersFunction", "Arn"]},
        "DeploymentBucket": {"Ref": "DeploymentBucket"},
        "S3Key": {"Ref": "SSLCertificateFile"}
      }
    },
    "ServerConfigStoreFunction": {
      "Type": "AWS::Lambda::Function",
      "DependsOn": "IAMRole",
      "Properties": {
        "Code": {
          "S3Bucket": {"Fn::Join" : ["", ["arcgisstore105", "-", {"Ref": "AWS::Region"}]]},
          "S3Key": "6491/lambda/arcgis-cfn-lambda-python3.zip"
        },
        "Handler": "server_config_store.handler",
        "Runtime": "python3.8",
        "Timeout": "30",
        "Role": { "Fn::GetAtt" : ["LambdaExecutionRole", "Arn"] }
      }
    },
    "ServerConfigStore": {
      "Type": "Custom::ServerConfigStore",
      "DependsOn": "ValidateSSLCertificateFile",
      "Properties": {
        "ServiceToken": {"Fn::GetAtt": ["ServerConfigStoreFunction", "Arn"]},
        "Namespace": {"Fn::Join" : ["", [{"Ref" : "AWS::StackName"}, "-", {"Ref": "FileServerEC2Instance"}]]}
      }
    },
    "DeploymentLogs": {
      "Type": "AWS::Logs::LogGroup",
      "DependsOn": "LambdaExecutionRole",
      "DeletionPolicy" : "Retain",
      "Properties": {
        "RetentionInDays": 7
      }
    },
    "ELB" : {
      "Type" : "AWS::ElasticLoadBalancing::LoadBalancer",
      "Properties" : {
        "Subnets" : [ {"Ref" : "Subnet1"}, {"Ref" : "Subnet2"} ],
        "SecurityGroups" : [ {"Ref" : "SecurityGroup"} ],
        "Scheme" : "internet-facing",
        "Listeners" : [ {
          "LoadBalancerPort" : "80",
          "InstancePort" : "80",
          "Protocol" : "HTTP"
        }, {
          "LoadBalancerPort" : "443",
          "InstancePort" : "443",
          "Protocol" : "TCP",
          "InstanceProtocol" : "TCP"
        } ],
        "HealthCheck" : {
          "Target" : "HTTP:6080/arcgis/rest/info/healthcheck",
          "HealthyThreshold" : "3",
          "UnhealthyThreshold" : "5",
          "Interval" : "30",
          "Timeout" : "5"
        },
        "Instances" : [{"Ref" : "PrimaryServerEC2Instance"}]
      }
    },
    "IAMRole" : {
      "Type" : "AWS::IAM::Role",
      "DependsOn": "LambdaExecutionRole",
      "Properties" : {
        "AssumeRolePolicyDocument" : {
          "Statement" : [ {
            "Effect" : "Allow",
            "Principal" : {
              "Service" : [ "ec2.amazonaws.com" ]
            },
            "Action" : [ "sts:AssumeRole" ]
          } ]
        },
        "Path" : "/"
      }
    },
    "IAMPolicy" : {
      "Type" : "AWS::IAM::Policy",
      "Properties" : {
        "PolicyName" : "IAMRole",
        "PolicyDocument" : {
          "Statement" : [ {
            "Action" : [ "s3:*", "dynamodb:*", "cloudformation:*", "logs:*" ],
            "Effect" : "Allow",
            "Resource" : "*"
          } ]
        },
        "Roles" : [ {
          "Ref" : "IAMRole"
        } ]
      }
    },
    "IAMInstanceProfile" : {
      "Type" : "AWS::IAM::InstanceProfile",
      "Properties" : {
        "Path" : "/",
        "Roles" : [ {
          "Ref" : "IAMRole"
        } ]
      }
    },
    "SecurityGroup" : {
      "Type" : "AWS::EC2::SecurityGroup",
      "Properties" : {
        "GroupDescription" : {"Ref" : "AWS::StackName"},
        "VpcId" : {"Ref" : "VPCId"},
        "SecurityGroupIngress" : [ {
          "IpProtocol" : "tcp",
          "FromPort" : "80",
          "ToPort" : "80",
          "CidrIp" : "0.0.0.0/0"
        }, {
          "IpProtocol" : "tcp",
          "FromPort" : "443",
          "ToPort" : "443",
          "CidrIp" : "0.0.0.0/0"
        } ]
      }
    },
    "SecurityGroupIngress" : {
      "Type" : "AWS::EC2::SecurityGroupIngress",
      "Properties" : {
        "GroupId" : {"Ref" : "SecurityGroup"},
        "IpProtocol" : "tcp",
        "FromPort" : "0",
        "ToPort" : "65535",
        "SourceSecurityGroupId" : {"Ref" : "SecurityGroup"}
      }
    },
    "FileServerEC2Instance" : {
      "Type" : "AWS::EC2::Instance",
      "Properties" : {
        "ImageId" : {"Fn::FindInMap" : ["RegionMap", {"Ref":"AWS::Region"}, "en"]},
        "InstanceType" : {"Ref":"FSInstanceType"},
        "KeyName" : {"Ref":"KeyName"},
        "IamInstanceProfile" : {"Ref":"IAMInstanceProfile"},
        "Monitoring" : true,
        "BlockDeviceMappings": [ {
          "DeviceName": "/dev/sda1",
          "Ebs": {
          "VolumeSize": {"Ref": "DriveSizeRoot"},
            "DeleteOnTermination": true,
            "VolumeType": "gp2"
          }
        }, {
          "DeviceName": "/dev/sdx",
          "Ebs": {
            "VolumeSize": {"Ref": "DriveSizeData"},
            "DeleteOnTermination": true,
            "VolumeType": "gp2"
          }
        },
        {"DeviceName": "xvdca", "NoDevice": {}}, {"DeviceName": "xvdcb", "NoDevice": {}},
        {"DeviceName": "xvdcc", "NoDevice": {}}, {"DeviceName": "xvdcd", "NoDevice": {}},
        {"DeviceName": "xvdce", "NoDevice": {}}, {"DeviceName": "xvdcf", "NoDevice": {}},
        {"DeviceName": "xvdcg", "NoDevice": {}}, {"DeviceName": "xvdch", "NoDevice": {}},
        {"DeviceName": "xvdci", "NoDevice": {}}, {"DeviceName": "xvdcj", "NoDevice": {}},
        {"DeviceName": "xvdck", "NoDevice": {}}, {"DeviceName": "xvdcl", "NoDevice": {}},
        {"DeviceName": "xvdcm", "NoDevice": {}}, {"DeviceName": "xvdcn", "NoDevice": {}},
        {"DeviceName": "xvdco", "NoDevice": {}}, {"DeviceName": "xvdcp", "NoDevice": {}},
        {"DeviceName": "xvdcq", "NoDevice": {}}, {"DeviceName": "xvdcr", "NoDevice": {}},
        {"DeviceName": "xvdcs", "NoDevice": {}}, {"DeviceName": "xvdct", "NoDevice": {}},
        {"DeviceName": "xvdcu", "NoDevice": {}}, {"DeviceName": "xvdcv", "NoDevice": {}},
        {"DeviceName": "xvdcw", "NoDevice": {}}, {"DeviceName": "xvdcx", "NoDevice": {}},
        {"DeviceName": "xvdcy", "NoDevice": {}}, {"DeviceName": "xvdcz", "NoDevice": {}} ],
        "Tags" : [{"Key" : "Name", "Value" : {"Fn::Join" : ["", [{"Ref" : "AWS::StackName"}, "-fileserver"]]}}],
        "NetworkInterfaces" : [{
          "GroupSet" : [{"Ref" : "SecurityGroup"}],
          "AssociatePublicIpAddress" : "true",
          "DeviceIndex" : "0",
          "DeleteOnTermination" : "true",
          "SubnetId" : {"Ref" : "Subnet1"}}],
        "UserData" : {
          "Fn::Base64" : {
            "Fn::Join" : ["", [
            "#!/bin/bash -v\n",
            "cfn-init -v -s ", {"Ref": "AWS::StackName"}, " -r FileServerEC2Instance", " --region ", {"Ref": "AWS::Region"}, "\n",
            "exitcode=$?\n",
            "wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py\n",
            "sudo python3 awslogs-agent-setup.py -n -r ", {"Ref": "AWS::Region"}, 
            " -c /tmp/cwlogs/cwlogs.conf || error_exit 'Failed to run CloudWatch Logs agent setup'\n",
            "if [ $exitcode -ne 0 ]; then\n",
            "  sleep 60\n",
            "  cfn-signal -e $exitcode -r 'cfn-init failed. See CloudWatch log group ", {"Ref": "DeploymentLogs"}, " for details.' '", 
            {"Ref": "FileServerWaitHandle"}, "'\n",
            "  exit $exitcode\n",
            "fi\n",
            "chmod 777 /mnt\n",
            "export arcgis_cloud_platform=aws\n",
            "chef-solo -j /tmp/node.json -r https://arcgisstore105.s3.amazonaws.com/6491/cookbooks/arcgis-2.3.1-cookbooks.tar.gz -L /var/log/chef-run.log -l info\n",
            "exitcode=$?\n",
            "if [ $exitcode -ne 0 ]; then\n",
            "  sleep 60\n",
            "  cfn-signal -e $exitcode -r 'Chef run failed. See CloudWatch log group ",
            {"Ref": "DeploymentLogs"}, " for details.' '", {"Ref": "FileServerWaitHandle"}, "'\n",
            "  exit $exitcode\n",
            "fi\n",
            "cfn-signal -e 0 -r 'Setup complete' '", {"Ref": "FileServerWaitHandle"}, "'\n"]]
          }
        }
      },
      "Metadata": {
        "AWS::CloudFormation::Authentication": {
           "S3AccessCreds": {
             "type": "S3",
             "buckets": [{"Ref": "DeploymentBucket"} ],
             "roleName": {"Ref": "IAMRole"}
          }
        },
        "AWS::CloudFormation::Init": {
          "config": {
            "files": {
              "/tmp/cwlogs/cwlogs.conf": {
                "content": {
                  "Fn::Join": ["", [
                  "[general]\n",
                  "state_file= /var/awslogs/agent-state\n",
                  "[/var/log/cfn-init.log]\n",
                  "file = /var/log/cfn-init.log\n",
                  "log_group_name = ", {"Ref": "DeploymentLogs"}, "\n",
                  "log_stream_name = {instance_id}/cfn-init.log\n",
                  "datetime_format = %d/%b/%Y:%H:%M:%S\n",
                  "[/var/log/chef-run.log]\n",
                  "file = /var/log/chef-run.log\n",
                  "log_group_name = ", {"Ref": "DeploymentLogs"}, "\n",
                  "log_stream_name = {instance_id}/chef-run.log\n",
                  "datetime_format = %Y-%m-%dT%H:%M:%S%z\n",
                  "[/var/lib/tomcat7/logs/catalina.out]\n",
                  "file = /var/lib/tomcat7/logs/catalina.out\n",
                  "log_group_name = ", {"Ref": "DeploymentLogs"}, "\n",
                  "log_stream_name = {instance_id}/catalina.out\n",
                  "datetime_format = %d/%b/%Y:%H:%M:%S"]]
                 },
                 "mode" : "000755"
               },
               "/tmp/node.json": {
                 "content" : {
                   "Fn::Join" : ["", [
                   "{\n",
                   "  \"arcgis\" : {\n",
                   "    \"server\" : {\n",
                   "      \"local_directories_root\" : \"/gisdata/arcgisserver\"\n",
                   "    }\n",
                   "  },\n",
                   "  \"run_list\" : [\n",
                   "    \"recipe[arcgis-server::system]\",\n",
                   "    \"recipe[arcgis-server::fileserver]\"]\n",
                   "}\n"]]
                 },
                 "mode" : "000755"
               }
            }
          }
        }
      }
    },
    "FileServerRecoveryAlarm" : {
      "Type" : "AWS::CloudWatch::Alarm",
      "Properties" : {
        "AlarmDescription" : "Trigger a recovery when instance status check fails for 5 consecutive minutes.",
        "MetricName" : "StatusCheckFailed_System",
        "Namespace" : "AWS/EC2",
        "Statistic" : "Minimum",
        "Period" : "60",
        "EvaluationPeriods" : "5",
        "Threshold" : "0",
        "ComparisonOperator" : "GreaterThanThreshold",
        "AlarmActions" : [ {"Fn::Join" : ["", ["arn:aws:automate:", { "Ref" : "AWS::Region" }, ":ec2:recover" ]]} ],
        "Dimensions" : [ {
          "Name" : "InstanceId",
          "Value" : {"Ref" : "FileServerEC2Instance"}
        } ]
      }
    },
    "PrimaryServerEC2Instance" : {
      "Type" : "AWS::EC2::Instance",
      "DependsOn" : "FileServerWaitCondition",
      "Properties" : {
        "ImageId" : {"Fn::FindInMap" : ["RegionMap", {"Ref":"AWS::Region"}, "en"]},
        "InstanceType" : {"Ref":"ASInstanceType"},
        "KeyName" : {"Ref":"KeyName"},
        "IamInstanceProfile" : {"Ref":"IAMInstanceProfile"},
        "Monitoring" : true,
        "BlockDeviceMappings": [ {
          "DeviceName": "/dev/sda1",
          "Ebs": {
          "VolumeSize": {"Ref": "DriveSizeRoot"},
            "DeleteOnTermination": true,
            "VolumeType": "gp2"
          }
        }, {
          "DeviceName": "/dev/sdx",
          "Ebs": {
            "VolumeSize": {"Ref": "DriveSizeData"},
            "DeleteOnTermination": true,
            "VolumeType": "gp2"
          }
        },
        {"DeviceName": "xvdca", "NoDevice": {}}, {"DeviceName": "xvdcb", "NoDevice": {}},
        {"DeviceName": "xvdcc", "NoDevice": {}}, {"DeviceName": "xvdcd", "NoDevice": {}},
        {"DeviceName": "xvdce", "NoDevice": {}}, {"DeviceName": "xvdcf", "NoDevice": {}},
        {"DeviceName": "xvdcg", "NoDevice": {}}, {"DeviceName": "xvdch", "NoDevice": {}},
        {"DeviceName": "xvdci", "NoDevice": {}}, {"DeviceName": "xvdcj", "NoDevice": {}},
        {"DeviceName": "xvdck", "NoDevice": {}}, {"DeviceName": "xvdcl", "NoDevice": {}},
        {"DeviceName": "xvdcm", "NoDevice": {}}, {"DeviceName": "xvdcn", "NoDevice": {}},
        {"DeviceName": "xvdco", "NoDevice": {}}, {"DeviceName": "xvdcp", "NoDevice": {}},
        {"DeviceName": "xvdcq", "NoDevice": {}}, {"DeviceName": "xvdcr", "NoDevice": {}},
        {"DeviceName": "xvdcs", "NoDevice": {}}, {"DeviceName": "xvdct", "NoDevice": {}},
        {"DeviceName": "xvdcu", "NoDevice": {}}, {"DeviceName": "xvdcv", "NoDevice": {}},
        {"DeviceName": "xvdcw", "NoDevice": {}}, {"DeviceName": "xvdcx", "NoDevice": {}},
        {"DeviceName": "xvdcy", "NoDevice": {}}, {"DeviceName": "xvdcz", "NoDevice": {}} ],
        "Tags" : [{"Key" : "Name", "Value" : {"Fn::Join" : ["", [{"Ref" : "AWS::StackName"}, "-primary"]]}}],
        "NetworkInterfaces" : [{
          "GroupSet" : [{"Ref" : "SecurityGroup"}],
          "AssociatePublicIpAddress" : "true",
          "DeviceIndex" : "0",
          "DeleteOnTermination" : "true",
          "SubnetId" : {"Ref" : "Subnet1"}}],
        "UserData" : {
          "Fn::Base64" : {
            "Fn::Join" : ["", [
            "#!/bin/bash -v\n",
            "cfn-init -v -c firstpass -s ", {"Ref": "AWS::StackName"}, " -r PrimaryServerEC2Instance", " --region ", {"Ref": "AWS::Region"}, "\n",
            "cfn-init -v -c secondpass -s ", {"Ref": "AWS::StackName"}, " -r PrimaryServerEC2Instance", " --region ", {"Ref": "AWS::Region"}, "\n",
            "exitcode=$?\n",
            "wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py\n",
            "sudo python3 awslogs-agent-setup.py -n -r ", {"Ref": "AWS::Region"}, 
            " -c /tmp/cwlogs/cwlogs.conf || error_exit 'Failed to run CloudWatch Logs agent setup'\n",
            "if [ $exitcode -ne 0 ]; then\n",
            "  sleep 60\n",
            "  cfn-signal -e $exitcode -r 'cfn-init failed. See CloudWatch log group ", {"Ref": "DeploymentLogs"}, " for details.' '", 
            {"Ref": "PrimaryServerWaitHandle"}, "'\n",
            "  exit $exitcode\n",
            "fi\n",
            "chmod 777 /mnt\n",
            "export arcgis_cloud_platform=aws\n",
            "chef-solo -j /tmp/node.json -r https://arcgisstore105.s3.amazonaws.com/6491/cookbooks/arcgis-2.3.1-cookbooks.tar.gz -L /var/log/chef-run.log -l info\n",
            "exitcode=$?\n",
            "if [ $exitcode -ne 0 ]; then\n",
            "  sleep 60\n",
            "  cfn-signal -e $exitcode -r 'Chef run failed. See CloudWatch log group ",
            {"Ref": "DeploymentLogs"}, " for details.' '", {"Ref": "PrimaryServerWaitHandle"}, "'\n",
            "  exit $exitcode\n",
            "fi\n",
            "cfn-signal -e 0 -r 'Setup complete' '", {"Ref": "PrimaryServerWaitHandle"}, "'\n"]]
          }
        }
      },
      "Metadata": {
        "AWS::CloudFormation::Authentication": {
          "S3AccessCreds": {
            "type": "S3",
            "buckets": [{"Ref": "DeploymentBucket"} ],
            "roleName": {"Ref": "IAMRole"}
          }
        },
        "AWS::CloudFormation::Init": {
          "configSets" : {
            "firstpass" : [ "config1" ],
            "secondpass" : [ "config2" ]
          },
          "config1": {
            "sources": {
              "/usr/local/lib/python3.6/dist-packages/cfnbootstrap/resources/documents" : "https://arcgisstore105.s3.amazonaws.com/endpoints.tar.gz"
            }
          },
          "config2": {
            "commands": {
              "rename-server-license": {
                "command": {"Fn::Join": ["", ["mv /tmp/server_license.tmp /tmp/", {"Ref": "ServerLicenseFile"}]]}
              }
            },
            "files": {
              "/tmp/cwlogs/cwlogs.conf": {
                "content": {"Fn::Join": ["", [
                  "[general]\n",
                  "state_file= /var/awslogs/agent-state\n",
                  "[/var/log/cfn-init.log]\n",
                  "file = /var/log/cfn-init.log\n",
                  "log_group_name = ", {"Ref": "DeploymentLogs"}, "\n",
                  "log_stream_name = {instance_id}/cfn-init.log\n",
                  "datetime_format = %d/%b/%Y:%H:%M:%S\n",
                  "[/var/log/chef-run.log]\n",
                  "file = /var/log/chef-run.log\n",
                  "log_group_name = ", {"Ref": "DeploymentLogs"}, "\n",
                  "log_stream_name = {instance_id}/chef-run.log\n",
                  "datetime_format = %Y-%m-%dT%H:%M:%S%z\n",
                  "[/var/lib/tomcat7/logs/catalina.out]\n",
                  "file = /var/lib/tomcat7/logs/catalina.out\n",
                  "log_group_name = ", {"Ref": "DeploymentLogs"}, "\n",
                  "log_stream_name = {instance_id}/catalina.out\n",
                  "datetime_format = %d/%b/%Y:%H:%M:%S"]]
                },
                "mode" : "000755"
              },
              "/etc/tomcat7/pkcs12_cert.pfx": {
                "source": {"Fn::GetAtt": [ "ValidateSSLCertificateFile", "S3ObjectURL" ]},
                "authentication": "S3AccessCreds",
                "mode" : "000755"
              },
              "/tmp/server_license.tmp": {
                "source": {"Fn::GetAtt": [ "ValidateServerLicenseFile", "S3ObjectURL" ]},
                "authentication": "S3AccessCreds",
                "mode" : "000755"
              },
              "/tmp/node.json": {
                "content" : {
                  "Fn::Join" : ["", [
                  "{\n",
                  "  \"java\" : {\n",
                  "    \"install_flavor\" : \"oracle\",\n",
                  "    \"jdk_version\" : \"8\",\n",
                  "    \"oracle\" : {\n",
                  "      \"accept_oracle_download_terms\" : true\n",
                  "    }\n",
                  "  },\n",
                  "  \"tomcat\" : {\n",
                  "    \"keystore_file\" : \"/etc/tomcat7/pkcs12_cert.pfx\",\n",
                  "    \"keystore_type\" : \"pkcs12\",\n",
                  "    \"keystore_password\" : \"", {"Ref": "SSLCertPassword"}, "\"\n",
                  "  },\n",
                  "  \"arcgis\" : {\n",
                  "    \"web_server\":{\n",
                  "      \"webapp_dir\":\"/opt/tomcat_arcgis/webapps\"\n",
                  "    },\n",
                  "    \"server\" : {\n",
                  "      \"admin_username\" : \"", {"Ref" : "SiteAdmin"}, "\",\n",
                  "      \"admin_password\" : \"", {"Ref" : "SiteAdminPassword" }, "\",\n",
                  "      \"authorization_file\" : \"/tmp/", {"Ref": "ServerLicenseFile"}, "\",\n",
                  "      \"directories_root\" : \"/net/", {"Fn::GetAtt" : ["FileServerEC2Instance", "PrivateIp"]}, "/gisdata/arcgisserver\",\n",
                  "      \"config_store_type\" : \"", {"Fn::If": ["UseCloudStore", "AMAZON", "FILESYSTEM"]}, "\",\r\n",
                  "      \"config_store_connection_string\" : \"", {"Fn::If": ["UseCloudStore",
                    {"Fn::Join" : ["", ["NAMESPACE=", {"Ref" : "AWS::StackName"}, ";REGION=", { "Ref" : "AWS::Region" } ]]},
                    {"Fn::Join" : ["", ["/net/", {"Fn::GetAtt" : [ "FileServerEC2Instance", "PrivateIp" ]}, "/gisdata/arcgisserver/config-store"]]}]}, "\",\n",
                  "      \"install_system_requirements\" : false\n",
                  "    },\n",
                  "    \"web_adaptor\" : {\n",
                  "      \"admin_access\" : true\n",
                  "    },\r\n",
                  "    \"rds\" : {\n",
                  "      \"engine\" : \"postgres\",\n",
                  "      \"endpoint\" : \"", {"Fn::If": ["CreateDBInstance", {"Fn::GetAtt": [ "DBInstance", "Endpoint.Address" ]}, ""]}, "\",\n",
                  "      \"username\" : \"EsriRDSAdmin\",\n",
                  "      \"password\" : \"", {"Ref" : "SiteAdminPassword" }, "\"\n",
                  "    }\n",
                  "  },\n",
                  "  \"run_list\" : [\n",
                  "    \"recipe[arcgis-server::system]\",\n",
                  "    \"recipe[arcgis-server::server]\",\n",
                  "    \"recipe[esri-tomcat]\",\n",
                  "    \"recipe[iptables]\",\n",
                  "    \"recipe[arcgis-server::iptables]\",\n",
                  "    \"recipe[arcgis-server::server_wa]\",\n",
                  "    \"recipe[arcgis-server::rds_egdb]\"]\n",
                  "}\n"]]
                }
              }
            }
          }
        }
      }
    },
    "PrimaryServerRecoveryAlarm" : {
      "Type" : "AWS::CloudWatch::Alarm",
      "Properties" : {
        "AlarmDescription" : "Trigger a recovery when instance status check fails for 5 consecutive minutes.",
        "MetricName" : "StatusCheckFailed_System",
        "Namespace" : "AWS/EC2",
        "Statistic" : "Minimum",
        "Period" : "60",
        "EvaluationPeriods" : "5",
        "Threshold" : "0",
        "ComparisonOperator" : "GreaterThanThreshold",
        "AlarmActions" : [ {"Fn::Join" : ["", ["arn:aws:automate:", { "Ref" : "AWS::Region" }, ":ec2:recover" ]]} ],
        "Dimensions" : [ {
          "Name" : "InstanceId",
          "Value" : {"Ref" : "PrimaryServerEC2Instance"}
        } ]
      }
    },
    "LaunchConfig" : {
      "Type" : "AWS::AutoScaling::LaunchConfiguration",
      "DependsOn" : "PrimaryServerWaitCondition",
      "Properties" : {
        "AssociatePublicIpAddress" : true,
        "ImageId" : {"Fn::FindInMap" : ["RegionMap", {"Ref":"AWS::Region"}, "en"]},
        "InstanceType" : {"Ref" : "ASInstanceType"},
        "KeyName" : {"Ref" : "KeyName"},
        "IamInstanceProfile" : {"Ref" : "IAMInstanceProfile"},
        "SecurityGroups" : [ {"Ref" : "SecurityGroup"} ],
        "InstanceMonitoring" : true,
        "BlockDeviceMappings": [ {
          "DeviceName": "/dev/sda1",
          "Ebs": {
            "VolumeSize": {"Ref": "DriveSizeRoot"},
            "DeleteOnTermination": true,
            "VolumeType": "gp2"
          }
        }, {
          "DeviceName": "/dev/sdx",
          "Ebs": {
            "VolumeSize": {"Ref": "DriveSizeData"},
            "DeleteOnTermination": true,
            "VolumeType": "gp2"
          }
        }],
        "UserData" : {
          "Fn::Base64" : {
            "Fn::Join" : ["", [
              "#!/bin/bash -v\n",
              "cfn-init -v -c firstpass -s ", {"Ref": "AWS::StackName"}, " -r LaunchConfig", " --region ", {"Ref": "AWS::Region"}, "\n",
              "cfn-init -v -c secondpass -s ", {"Ref": "AWS::StackName"}, " -r LaunchConfig", " --region ", {"Ref": "AWS::Region"}, "\n",
              "exitcode=$?\n",
              "wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py\n",
              "sudo python3 awslogs-agent-setup.py -n -r ", {"Ref": "AWS::Region"}, 
              " -c /tmp/cwlogs/cwlogs.conf || error_exit 'Failed to run CloudWatch Logs agent setup'\n",
              "if [ $exitcode -ne 0 ]; then\n",
              "  sleep 60\n",
              "  cfn-signal -e $exitcode -r 'cfn-init failed. See CloudWatch log group ", {"Ref": "DeploymentLogs"}, " for details.' '", 
              {"Ref": "AutoScalingGroupWaitHandle"}, "'\n",
              "  exit $exitcode\n",
              "fi\n",
              "chmod 777 /mnt\n",
              "export arcgis_cloud_platform=aws\n",
              "chef-solo -j /tmp/node.json -r https://arcgisstore105.s3.amazonaws.com/6491/cookbooks/arcgis-2.3.1-cookbooks.tar.gz -L /var/log/chef-run.log -l info\n",
              "exitcode=$?\n",
              "if [ $exitcode -ne 0 ]; then\n",
              "  sleep 60\n",
              "  cfn-signal -e $exitcode -r 'Chef run failed. See CloudWatch log group ",
              {"Ref": "DeploymentLogs"}, " for details.' '", {"Ref": "AutoScalingGroupWaitHandle"}, "'\n",
              "  exit $exitcode\n",
              "fi\n",
              "cfn-signal -e 0 -r 'Setup complete' '", {"Ref": "AutoScalingGroupWaitHandle"}, "'\n"]
            ]
          }
        }
      },
      "Metadata" : {
        "AWS::CloudFormation::Authentication" : {
          "S3AccessCreds" : {
            "type" : "S3",
            "buckets" : [ {"Ref" : "DeploymentBucket"} ],
            "roleName" : {"Ref" : "IAMRole"}
          }
        },
        "AWS::CloudFormation::Init" : {
          "configSets" : {
            "firstpass" : [ "config1" ],
            "secondpass" : [ "config2" ]
          },
          "config1": {
            "sources": {
              "/usr/local/lib/python3.6/dist-packages/cfnbootstrap/resources/documents" : "https://arcgisstore105.s3.amazonaws.com/endpoints.tar.gz"
            }
          },
          "config2": {
            "commands": {
              "rename-server-license": {
                 "command": {"Fn::Join": ["", ["mv /tmp/server_license.tmp /tmp/", {"Ref": "ServerLicenseFile"}]]}
              }
            },
            "files": {
              "/tmp/cwlogs/cwlogs.conf": {
                "content": {
                  "Fn::Join": ["", [
                  "[general]\n",
                  "state_file= /var/awslogs/agent-state\n",
                  "[/var/log/cfn-init.log]\n",
                  "file = /var/log/cfn-init.log\n",
                  "log_group_name = ", {"Ref": "DeploymentLogs"}, "\n",
                  "log_stream_name = {instance_id}/cfn-init.log\n",
                  "datetime_format = %d/%b/%Y:%H:%M:%S\n",
                  "[/var/log/chef-run.log]\n",
                  "file = /var/log/chef-run.log\n",
                  "log_group_name = ", {"Ref": "DeploymentLogs"}, "\n",
                  "log_stream_name = {instance_id}/chef-run.log\n",
                  "datetime_format = %Y-%m-%dT%H:%M:%S%z\n",
                  "[/var/lib/tomcat7/logs/catalina.out]\n",
                  "file = /var/lib/tomcat7/logs/catalina.out\n",
                  "log_group_name = ", {"Ref": "DeploymentLogs"}, "\n",
                  "log_stream_name = {instance_id}/catalina.out\n",
                  "datetime_format = %d/%b/%Y:%H:%M:%S"]]
                },
                "mode" : "000755"
              },
              "/etc/tomcat7/pkcs12_cert.pfx": {
                "source": {"Fn::GetAtt": [ "ValidateSSLCertificateFile", "S3ObjectURL" ]},
                "authentication": "S3AccessCreds",
                "mode" : "000755"
              },
              "/tmp/server_license.tmp": {
                "source": {"Fn::GetAtt": [ "ValidateServerLicenseFile", "S3ObjectURL" ]},
                "authentication": "S3AccessCreds",
                "mode" : "000755"
              },
              "/tmp/node.json": {
                "content" : {
                  "Fn::Join" : [ "", [ 
                  "{\n", 
                  "  \"java\" : {\n",
                  "    \"install_flavor\" : \"oracle\",\n",
                  "    \"jdk_version\" : \"8\",\n",
                  "    \"oracle\" : {\n",
                  "      \"accept_oracle_download_terms\" : true\n",
                  "    }\n",
                  "  },\n",
                  "  \"tomcat\" : {\n",
                  "    \"keystore_file\" : \"/etc/tomcat7/pkcs12_cert.pfx\",\n",
                  "    \"keystore_type\" : \"pkcs12\",\n",
                  "    \"keystore_password\" : \"", {"Ref": "SSLCertPassword"}, "\"\n",
                  "  },\n",
                  "  \"arcgis\" : {\n",
                  "    \"web_server\":{\n",
                  "      \"webapp_dir\":\"/opt/tomcat_arcgis/webapps\"\n",
                  "    },\n",
                  "    \"server\" : {\n", 
                  "      \"admin_username\" : \"", {"Ref" : "SiteAdmin"}, "\",\n", 
                  "      \"admin_password\" : \"", {"Ref" : "SiteAdminPassword" }, "\",\n",
                  "      \"authorization_file\" : \"/tmp/", {"Ref": "ServerLicenseFile"}, "\",\n",
                  "      \"primary_server_url\" : \"http://", { "Fn::GetAtt" : [ "PrimaryServerEC2Instance", "PrivateIp" ] }, ":6080/arcgis\",\n",
                  "      \"use_join_site_tool\" : true,\n",
                  "      \"config_store_type\" : \"", {"Fn::If": ["UseCloudStore", "AMAZON", "FILESYSTEM"]}, "\",\r\n",
                  "      \"config_store_connection_string\" : \"", {"Fn::If": ["UseCloudStore",
                    {"Fn::Join" : ["", ["NAMESPACE=", {"Ref" : "AWS::StackName"}, ";REGION=", { "Ref" : "AWS::Region" } ]]},
                    {"Fn::Join" : ["", ["/net/", {"Fn::GetAtt" : [ "FileServerEC2Instance", "PrivateIp" ]}, "/gisdata/arcgisserver/config-store"]]}]}, "\",\n",
                  "      \"install_system_requirements\" : false\n",
                  "    },\n", 
                  "    \"web_adaptor\" : {\n",
                  "      \"admin_access\" : true\n",
                  "    }\r\n",
                  "  },\n",
                  "  \"run_list\" : [\n", 
                  "    \"recipe[arcgis-server::system]\",\n",
                  "    \"recipe[arcgis-server::server_node]\",\n",
                  "    \"recipe[esri-tomcat]\",\n",
                  "    \"recipe[iptables]\",\n",
                  "    \"recipe[arcgis-server::iptables]\",\n",
                  "    \"recipe[arcgis-server::server_wa]\"]\n", 
                  "}\n" ] ]
                },
                "mode" : "000755"
              }
            }
          }
        }
      }
    },
    "AutoScalingGroup" : {
      "Type" : "AWS::AutoScaling::AutoScalingGroup",
      "DependsOn" : "FileServerEC2Instance",
      "Properties" : {
        "VPCZoneIdentifier" : [ {"Ref" : "Subnet2"} ],
        "Cooldown" : "300",
        "MaxSize" : {"Ref" : "SecondaryInstances"},
        "MinSize" : {"Ref" : "SecondaryInstances"},
        "LaunchConfigurationName" : {"Ref" : "LaunchConfig"},
        "HealthCheckType" : "EC2",
        "HealthCheckGracePeriod" : "3600",
        "LoadBalancerNames" : [ {"Ref" : "ELB"} ],
        "Tags" : [ {
          "Key" : "Name",
          "Value" : {"Fn::Join" : ["", [{"Ref" : "AWS::StackName"}, "-secondary"]]},
          "PropagateAtLaunch" : true
        } ]
      },
      "UpdatePolicy": {
        "AutoScalingReplacingUpdate": {
          "WillReplace": "true"
        }
      }
    },
    "FileServerWaitHandle" : {
      "Type" : "AWS::CloudFormation::WaitConditionHandle",
      "Properties" : {}
    },
    "FileServerWaitCondition" : {
      "Type" : "AWS::CloudFormation::WaitCondition",
      "Properties" : {
        "Count" : "1",
        "Handle" : {"Ref" : "FileServerWaitHandle"},
        "Timeout" : "7200"
      }
    },
    "PrimaryServerWaitHandle" : {
      "Type" : "AWS::CloudFormation::WaitConditionHandle",
      "Properties" : {}
    },
    "PrimaryServerWaitCondition" : {
      "Type" : "AWS::CloudFormation::WaitCondition",
      "Properties" : {
        "Count" : "1",
        "Handle" : {"Ref" : "PrimaryServerWaitHandle"},
        "Timeout" : "10800"
      }
    },
    "AutoScalingGroupWaitHandle" : {
      "Type" : "AWS::CloudFormation::WaitConditionHandle",
      "Properties" : {}
    },
    "AutoScalingGroupWaitCondition" : {
      "Type" : "AWS::CloudFormation::WaitCondition",
      "Properties" : {
        "Count" : {"Ref" : "SecondaryInstances"},
        "Handle" : {"Ref" : "AutoScalingGroupWaitHandle"},
        "Timeout" : "10800"
      }
    },
    "CloudWatchSettings" : {
      "Type" : "AWS::Logs::MetricFilter",
      "DeletionPolicy" : "Retain",
      "Properties": {
        "LogGroupName": {"Ref": "DeploymentLogs"},
        "FilterPattern": "[level=FATAL, message]",
        "MetricTransformations": [{
           "MetricValue": "1",
           "MetricNamespace": "ArcGIS/Deployment",
           "MetricName": "ErrorCount"
        }]
      }
    },
    "DBSubnetGroup" : {
      "Type" : "AWS::RDS::DBSubnetGroup",
      "Condition": "CreateDBInstance",
      "Properties" : {
        "DBSubnetGroupDescription" : "DB subnet group",
        "SubnetIds" : [ {"Ref": "Subnet1"}, {"Ref": "Subnet2"} ],
        "Tags" : [{"Key" : "Name", "Value" : {"Fn::Join" : ["", [{"Ref" : "AWS::StackName"}, "-db"]]}}]
      }
    },
    "DBInstance" : {
      "Type" : "AWS::RDS::DBInstance",
      "Condition": "CreateDBInstance",
      "Properties" : {
        "AllocatedStorage" : {"Ref": "DBAllocatedStorage"},
        "DBInstanceClass" : {"Ref" : "DBInstanceClass"},
        "Engine" : {"Ref": "DBEngine"},
        "EngineVersion" : {"Fn::FindInMap" : ["DBEngineProperties", {"Ref": "DBEngine"}, "Version"]},
        "LicenseModel": {"Fn::FindInMap" : ["DBEngineProperties", {"Ref": "DBEngine"}, "License"]},
        "MultiAZ" : {"Fn::If": ["DBEnginePostgres", "true", {"Ref": "AWS::NoValue"}]},
        "DBSubnetGroupName": {"Ref": "DBSubnetGroup"},
        "VPCSecurityGroups": [{"Ref": "SecurityGroup"}],
        "StorageType": "gp2",
        "MasterUsername" : "EsriRDSAdmin",
        "MasterUserPassword" : { "Ref" : "SiteAdminPassword" },
        "Tags" : [{"Key" : "Name", "Value" : {"Fn::Join" : ["", [{"Ref" : "AWS::StackName"}, "-db"]]}}]
      }
    }
  },
  "Outputs" : {
    "ManagerURL" : {
      "Value" : {"Fn::Join" : [ "", [ "https://", {"Fn::GetAtt" : ["ELB", "DNSName"]}, "/server/manager" ]]},
      "Description" : "ArcGIS Server Manager URL"
    },
    "RestURL" : {
      "Value" : {"Fn::Join" : [ "", [ "https://", {"Fn::GetAtt" : ["ELB", "DNSName"]}, "/server/rest" ]]},
      "Description" : "ArcGIS REST Services Directory URL"
    },
    "LogsURL" : {
      "Value" : {"Fn::Join" : [ "", [ "https://console.aws.amazon.com/cloudwatch/home?region=", {"Ref" : "AWS::Region"}, "#logStream:group=", {"Ref" : "DeploymentLogs"}]]},
      "Description" : "Deployment Logs"
    },
    "DNSName" : {
      "Description" : "Elastic load balancer DNS name",
      "Value" :  {"Fn::GetAtt" : ["ELB", "DNSName"]}
    }
  }
}