{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "ArcGIS CloudFormation Template: Provisions spatiotemporal ArcGIS Data Store on EC2 instances running Ubuntu Linux 16.04 LTS. **WARNING** You will be billed by AWS for the AWS resources if you create a stack from this template.",
    "Mappings" : {
        "RegionMap" : {
			"ap-south-1": {
			  "en": "ami-0635cf946e11106fc"
			},
			"eu-west-3": {
			  "en": "ami-0fe069df45925e438"
			},
			"eu-west-2": {
			  "en": "ami-08a8a3187e4a42ad3"
			},
			"eu-west-1": {
			  "en": "ami-012a21cb9831d61ad"
			},
			"ap-northeast-2": {
			  "en": "ami-0b8ec5210df694aab"
			},
			"ap-northeast-1": {
			  "en": "ami-0578abab299105f7d"
			},
			"sa-east-1": {
			  "en": "ami-06b800e914f563555"
			},
			"ca-central-1": {
			  "en": "ami-0bf8520ac886e1d29"
			},
			"ap-southeast-1": {
			  "en": "ami-02bfa41bd71aab1a2"
			},
			"ap-southeast-2": {
			  "en": "ami-088d9573194b87bd9"
			},
			"eu-central-1": {
			  "en": "ami-052e46eeca6e66646"
			},
			"us-east-1": {
			  "en": "ami-09a4a8ee6b8d1d307"
			},
			"us-east-2": {
			  "en": "ami-0208a260e46763f99"
			},
			"us-west-1": {
			  "en": "ami-038c8262da6997c0b"
			},
			"us-west-2": {
			  "en": "ami-0af6ca81b66f0633a"
			},
			"us-gov-west-1": {
			  "en": "ami-bc990bdd"
			}
    }
    },
    "Parameters": {
        "DeploymentBucket": {
            "Description": "S3 bucket for license files and SSL certificates",
            "Type": "String",
            "AllowedPattern": "^([a-z]|(\\d(?!\\d{0,2}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})))([a-z\\d]|(\\.(?!(\\.|-)))|(-(?!\\.))){1,61}[a-z\\d\\.]$",
            "ConstraintDescription": "A Bucket's name can be between 6 and 63 characters long, containing lowercase characters, numbers, periods, and dashes and it must start with a lowercase letter or number."
        },
        "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. "
        },
        "BDSInstanceType": {
             "Description": "Spatiotemporal Big Data Store EC2 instance type",
             "Type": "String",
             "AllowedValues": [
                "m3.large", "m3.xlarge", "m3.2xlarge",
                "m4.large", "m4.xlarge", "m4.2xlarge", "m4.4xlarge", "m4.10xlarge",
                "m5.large", "m5.xlarge", "m5.2xlarge", "m5.4xlarge", "m5.12xlarge", "m5.24xlarge",
                "m5d.large", "m5d.xlarge", "m5d.2xlarge", "m5d.4xlarge", "m5d.12xlarge", "m5d.24xlarge",
                "c3.large", "c3.xlarge", "c3.2xlarge", "c3.4xlarge", "c3.8xlarge",
                "c4.large", "c4.xlarge", "c4.2xlarge", "c4.4xlarge", "c4.8xlarge",
                "c5.large", "c5.xlarge", "c5.2xlarge", "c5.4xlarge", "c5.9xlarge", "c5.18xlarge",
                "c5d.large", "c5d.xlarge", "c5d.2xlarge", "c5d.4xlarge", "c5d.9xlarge", "c5d.18xlarge",
                "r3.large", "r3.xlarge", "r3.2xlarge", "r3.4xlarge", "r3.8xlarge",
                "r4.large", "r4.xlarge", "r4.2xlarge", "r4.4xlarge", "r4.8xlarge", "r4.16xlarge",
        		"r5.large", "r5.xlarge", "r5.2xlarge", "r5.4xlarge", "r5.12xlarge", "r5.24xlarge",
				"r5d.large", "r5d.xlarge", "r5d.2xlarge", "r5d.4xlarge", "r5d.12xlarge", "r5d.24xlarge",
				"t2.large", "t2.xlarge", "t2.2xlarge",
                "x1.16xlarge", "x1.32xlarge"
             ],
            "Default": "m4.xlarge"
        },
        "ServerInstancePrivateIp": {
          "Description": "Private IP address of ArcGIS server EC2 instance.",
          "Type": "String"
        },
        "BDSInstances" : {
            "Description" : "Number of spatiotemporal Big Data Store EC2 instances",
            "Type" : "Number",
            "Default" : "0",
            "AllowedValues" : [0, 1]
        },
        "KeyName": {
            "Description": "The EC2 KeyPair to allow remote access to the instances",
            "Type": "AWS::EC2::KeyPair::KeyName"
        },
        "SiteAdmin": {
            "Description": "User name for ArcGIS Server site admin and Portal initial admin accounts",
            "Type": "String",
            "Default": "admin",
            "AllowedPattern": "^[a-zA-Z][a-zA-Z0-9_]{4,}$",
            "ConstraintDescription": "User name must be 4 or more alphanumeric or underscore (_) characters and must start with a letter."
        },
        "SiteAdminPassword": {
            "Description": "Password for the site admin account",
            "Type": "String",
            "NoEcho": "true",
            "AllowedPattern": "^[a-zA-Z0-9_\\.@]{8,}$",
            "ConstraintDescription": "Password must be 8 or more alphanumeric, underscore (_), at ('@'), or dot (.) characters."
        },
        "SecurityGroupId" : {
            "Description" : "ID of the EC2 security group.",
            "Type" : "AWS::EC2::SecurityGroup::Id"
        },
        "VPCId" : {
            "Description" : "VPC ID",
            "Type" : "AWS::EC2::VPC::Id" 
        },
        "Subnets" : {
          "Description" : "VPC Subnets",
          "Type": "List<AWS::EC2::Subnet::Id>"
        },
        "PostInstallationScript": {
            "Description": "ZIP archive file with custom post installation script (must be uploaded to DeploymentBucket).",
            "Type": "String",
            "AllowedPattern": "[^\"]{1,1024}",
            "ConstraintDescription": "S3 object key name must be between 1 and 1024 characters.",
            "Default": "none"
        }
    },
    "Metadata" : {
      "AWS::CloudFormation::Interface" : {
        "ParameterGroups" : [ {
          "Label" : { "default" : "Network Configuration" },
          "Parameters" : [ "VPCId", "Subnets", "SecurityGroupId" ]
        },
        {
          "Label" : { "default":"Amazon EC2 Configuration" },
          "Parameters" : [ "BDSInstanceType", "BDSInstances", "DriveSizeRoot", "DriveSizeData", "KeyName" ]
        },
        {
          "Label" : { "default":"ArcGIS Enterprise Configuration" },
          "Parameters" : [ "DeploymentBucket", "ServerInstancePrivateIp", "SiteAdmin", "SiteAdminPassword", "RunAsUserPassword" ]
        } ]
      }
    },
    "Conditions" : {
        "RunPostInstall" : {"Fn::Not" : [{"Fn::Equals" : [{"Ref" : "PostInstallationScript"}, "none"]}]}
    },
    "Resources": {
        "ValidateParametersFunction": {
          "Type": "AWS::Lambda::Function",
          "DependsOn": "IAMRole",
          "Properties": {
            "Code": {
              "S3Bucket": {"Fn::Join" : ["", ["arcgisstore1061", "-", {"Ref": "AWS::Region"}]]},
              "S3Key": "9270/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": "*"
                },
                {
                  "Effect": "Allow",
                  "Action": ["s3:*"],
                  "Resource": "*"
                },
                {
                  "Effect": "Allow",
                  "Action": ["ec2:*"],
                  "Resource": "*"
                },
                {
                  "Effect": "Allow",
                  "Action": ["cloudformation:*"],
                  "Resource": "*"
                },
                {
                  "Effect": "Allow",
                  "Action": ["autoscaling:*"],
                  "Resource": "*"
                }]
              }
            }]
          }
        },
        "ValidatePostInstallationScript": {
          "Type": "Custom::ValidateParameters",
          "Condition": "RunPostInstall",
          "Properties": {
            "ServiceToken": {"Fn::GetAtt": ["ValidateParametersFunction", "Arn"]},
            "DeploymentBucket": {"Ref": "DeploymentBucket"},
            "S3Key": {"Ref": "PostInstallationScript"}
          }
        },
        "DeploymentLogs": {
            "Type": "AWS::Logs::LogGroup",
            "Properties": {
                "RetentionInDays": 7
            }
        },
        "IAMRole": {
            "Type": "AWS::IAM::Role",
            "DependsOn": "LambdaExecutionRole",
            "Properties": {
                "AssumeRolePolicyDocument": {
                    "Statement": [ {
                        "Effect": "Allow",
                        "Principal": {
                            "Service": [ "ec2.amazonaws.com", "ssm.amazonaws.com" ]
                        },
                        "Action": [ "sts:AssumeRole" ]
                    } ]
                },
                "Path": "/"
            }
        },
        "IAMPolicy": {
            "Type": "AWS::IAM::Policy",
            "Properties": {
                "PolicyName": "IAMRole",
                "PolicyDocument": {
                    "Statement": [ {
                            "Action": [ "s3:*", "cloudformation:*", "logs:*", "ssm:*", "ec2messages:*" ],
                            "Effect": "Allow",
                            "Resource": "*"
                        }
                    ]
                },
                "Roles": [ {"Ref": "IAMRole"} ]
            }
        },
        "IAMInstanceProfile": {
            "Type": "AWS::IAM::InstanceProfile",
            "Properties": {
                "Path": "/",
                "Roles": [ {"Ref": "IAMRole"} ]
            }
        },
        "LaunchConfig" : {
          "Type" : "AWS::AutoScaling::LaunchConfiguration",
          "Properties" : {
            "AssociatePublicIpAddress" : true,
            "ImageId" : {"Fn::FindInMap" : ["RegionMap", {"Ref":"AWS::Region"}, "en"]},
            "InstanceType" : {"Ref" : "BDSInstanceType"},
            "KeyName" : {"Ref" : "KeyName"},
            "IamInstanceProfile" : {"Ref" : "IAMInstanceProfile"},
            "SecurityGroups" : [ {"Ref": "SecurityGroupId"} ],
            "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",
                  "sudo resize2fs /dev/disk/by-label/gisdata || true\n",
                  "for i in {1..60}; do ping -c1 $(hostname); if [ $? -eq 0 ]; then break; fi; sleep 10; done\n",
                  "ping -c1 $(hostname)\n",
                  "exitcode=$?\n", 
                  "if [ $exitcode -ne 0 ]; then\n",
                  "  cfn-signal -e $exitcode -r 'Failed to resolve the host name. Check the VPC settings.' '", {"Ref": "AutoScalingGroupWaitHandle"}, "'\n",
                  "  exit $exitcode\n",
                  "fi\n",
                  "if ", {"Fn::If": ["RunPostInstall", "true", "false"]}, "; then\n",
                  "  cfn-init -v -c post-install-script -s ", {"Ref": "AWS::StackName"}, " -r LaunchConfig", " --region ", {"Ref": "AWS::Region"}, "\n",
                  "fi\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",
                  "  cfn-signal -e $exitcode -r 'cfn-init failed. See /var/log/cfn-init.log for details.' '", 
                  {"Ref": "AutoScalingGroupWaitHandle"}, "'\n",
                  "  exit $exitcode\n",
                  "fi\n",
                  "chmod 777 /mnt\n",
                  "export arcgis_cloud_platform=aws\n",
                  "chef-solo -j /etc/chef/node.json -r https://arcgisstore1061.s3.amazonaws.com/9270/cookbooks/arcgis-3.2.1-cookbooks.tar.gz -L /var/log/chef-run.log -l info\n",
                  "exitcode=$?\n",
                  "if [ $exitcode -ne 0 ]; then\n",
                  "  cfn-signal -e $exitcode -r 'Chef run failed. See /var/log/chef-run.log 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" ],
                "post-install-script": ["post-install-config"]
              },
              "post-install-config": {
                "sources" : {
                  "/arcgis/postinstallscripts" : {"Fn::If": ["RunPostInstall", {"Fn::GetAtt": [ "ValidatePostInstallationScript", "S3ObjectURL" ]}, ""]}
                }
              }, 
              "config1": {
                "sources": {
                  "/usr/local/lib/python3.6/dist-packages/cfnbootstrap/resources/documents" : "https://arcgisstore1061.s3.amazonaws.com/endpoints.tar.gz"
                }
              },
              "config2": {
                "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/chef/node.json" : {
                    "content" : {
                      "Fn::Join" : [ "", [
                      "{\n",
                      "  \"arcgis\" : {\n",
                      "    \"version\": \"10.6.1\",\n",
                      "    \"post_install_script\" : \"/arcgis/postinstallscripts/deploy.sh\",\n",
                      "    \"server\" : {\n",
                      "      \"admin_username\" : \"", {"Ref" : "SiteAdmin"}, "\",\n",
                      "      \"admin_password\" : \"", {"Ref" : "SiteAdminPassword"}, "\",\n",
                      "      \"domain_name\" : \"", {"Ref" : "ServerInstancePrivateIp"}, "\"\n",
                      "    },\n",
                      "    \"data_store\" : {\n",
                      "      \"types\" : \"spatiotemporal\",\n",
                      "      \"preferredidentifier\" : \"ip\",\n",
                      "      \"data_dir\" : \"/gisdata/arcgisdatastore\"\n",
                      "    }\n",
                      "  },\n",
                      "  \"run_list\" : [\n",
                      "    \"recipe[apt]\",\n",
                      "    \"recipe[arcgis-enterprise::hosts]\",\n",
                      "    \"recipe[arcgis-enterprise::datastore]\",\n",
                      "    \"recipe[arcgis-enterprise::post_install]\"]\n",
                      "}\n" ] ]
                    },
                    "mode" : "000755"
                  }
                }
              }
            }
          }
        },
       "AutoScalingGroup" : {
         "Type" : "AWS::AutoScaling::AutoScalingGroup",
         "Properties" : {
           "VPCZoneIdentifier" : {"Ref" : "Subnets"},
           "Cooldown" : "300",
           "MaxSize" : {"Ref" : "BDSInstances"},
           "MinSize" : {"Ref" : "BDSInstances"},
           "LaunchConfigurationName" : {"Ref" : "LaunchConfig"},
           "HealthCheckType" : "EC2",
           "HealthCheckGracePeriod" : "3600",
           "Tags" : [ {
             "Key" : "Name",
             "Value" : {"Fn::Join" : ["", [{"Ref" : "AWS::StackName"}, "-bds"]]},
             "PropagateAtLaunch" : true
           } ]
         },
         "UpdatePolicy": {
           "AutoScalingReplacingUpdate": {
             "WillReplace": "true"
           }
         }
       },
       "AutoScalingGroupWaitHandle" : {
         "Type" : "AWS::CloudFormation::WaitConditionHandle",
         "Properties" : {}
       },
       "AutoScalingGroupWaitCondition" : {
         "Type" : "AWS::CloudFormation::WaitCondition",
         "DependsOn" : "LaunchConfig",
         "Properties" : {
           "Count" : {"Ref" : "BDSInstances"},
           "Handle" : {"Ref" : "AutoScalingGroupWaitHandle"},
           "Timeout" : "10800"
         }
       },
       "CloudWatchSettings": {
            "Type": "AWS::Logs::MetricFilter",
            "Properties": {
                "LogGroupName": {"Ref": "DeploymentLogs"},
                "FilterPattern": "[level=FATAL, message]",
                "MetricTransformations": [
                    {
                        "MetricValue": "1",
                        "MetricNamespace": "ArcGIS/Deployment",
                        "MetricName": "ErrorCount"
                    }
                ]
            },
            "Metadata": {
                "AWS::CloudFormation::Authentication": {
                    "S3AccessCreds": {
                        "type": "S3",
                        "buckets": [{"Ref": "DeploymentBucket"}],
                        "roleName": {"Ref": "IAMRole"}
                    }
                },
                "AWS::CloudFormation::Init": {
                    "configSets" : {
                        "default": ["config"],
                        "post-install-script": ["post-install-config"]
                    },
                    "post-install-config": {
                        "sources" : {
                            "D:\\PostInstallScripts" : {"Fn::If": ["RunPostInstall", {"Fn::GetAtt": [ "ValidatePostInstallationScript", "S3ObjectURL" ]}, ""]}
                        }
                    },
                    "config": {
                        "sources": {
                            "C:\\chef": "https://arcgisstore1061.s3.amazonaws.com/9270/cookbooks/arcgis-3.2.1-cookbooks.zip",
                            "C:\\Program Files\\Amazon\\cfn-bootstrap" : "https://arcgisstore1061.s3.amazonaws.com/endpoints.tar.gz"
                        },
                        "files": {
                          "C:\\Program Files\\Amazon\\SSM\\Plugins\\awsCloudWatch\\AWS.EC2.Windows.CloudWatch.json": {
                            "content": {
                              "Fn::Join" : ["", [
                              "{\r\n",
                              "  \"IsEnabled\" : true,\r\n",
                              "  \"EngineConfiguration\": {\r\n",
                              "    \"PollInterval\": \"00:00:15\",\r\n",
                              "    \"Components\": [\r\n",
                              "    {\r\n",
                              "      \"Id\": \"CfnInitLogStream\",\r\n",
                              "      \"FullName\": \"AWS.EC2.Windows.CloudWatch.CloudWatchLogsOutput,AWS.EC2.Windows.CloudWatch\",\r\n",
                              "      \"Parameters\": {\r\n",
                              "        \"Region\": \"", {"Ref" : "AWS::Region"}, "\",\r\n",
                              "        \"LogGroup\": \"", {"Ref": "DeploymentLogs"}, "\",\r\n",
                              "        \"LogStream\": \"{instance_id}/cfn-init.log\"\r\n",
                              "      }\r\n",
                              "    },\r\n",
                              "    {\r\n",
                              "      \"Id\": \"ChefRunLogStream\",\r\n",
                              "      \"FullName\": \"AWS.EC2.Windows.CloudWatch.CloudWatchLogsOutput,AWS.EC2.Windows.CloudWatch\",\r\n",
                              "      \"Parameters\": {\r\n",
                              "        \"Region\": \"", {"Ref" : "AWS::Region"}, "\",\r\n",
                              "        \"LogGroup\": \"", {"Ref": "DeploymentLogs"}, "\",\r\n",
                              "        \"LogStream\": \"{instance_id}/chef-run.log\"\r\n",
                              "      }\r\n",
                              "    },\r\n",
                              "    {\r\n",
                              "      \"Id\": \"CfnInitLogs\",\r\n",
                              "      \"FullName\": \"AWS.EC2.Windows.CloudWatch.CustomLog.CustomLogInputComponent,AWS.EC2.Windows.CloudWatch\",\r\n",
                              "      \"Parameters\": {\r\n",
                              "        \"LogDirectoryPath\": \"C:\\\\cfn\\\\log\",\r\n",
                              "        \"TimestampFormat\": \"yyyy-MM-dd HH:mm:ss,fff\",\r\n",
                              "        \"Encoding\": \"UTF-8\",\r\n",
                              "        \"Filter\": \"cfn-init.log\",\r\n",
                              "        \"CultureName\": \"en-US\",\r\n",
                              "        \"TimeZoneKind\": \"Local\",\r\n",
                              "        \"LineCount\": \"1\"\r\n",
                              "      }\r\n",
                              "    },\r\n",
                              "    {\r\n",
                              "      \"Id\": \"ChefRunLogs\",\r\n",
                              "      \"FullName\": \"AWS.EC2.Windows.CloudWatch.CustomLog.CustomLogInputComponent,AWS.EC2.Windows.CloudWatch\",\r\n",
                              "      \"Parameters\": {\r\n",
                              "        \"LogDirectoryPath\": \"C:\\\\chef\",\r\n",
                              "        \"TimestampFormat\": \"[yyyy-MM-ddTHH:mm:sszzz]\",\r\n",
                              "        \"Encoding\": \"UTF-8\",\r\n",
                              "        \"Filter\": \"chef-run.log\",\r\n",
                              "        \"CultureName\": \"en-US\",\r\n",
                              "        \"TimeZoneKind\": \"Local\",\r\n",
                              "        \"LineCount\": \"1\"\r\n",
                              "      }\r\n",
                              "    }],\r\n",
                              "    \"Flows\": {\r\n",
                              "      \"Flows\":[\"CfnInitLogs,CfnInitLogStream\",\"ChefRunLogs,ChefRunLogStream\"]\r\n",
                              "    }\r\n",
                              "  }\r\n",
                              "}\r\n"]]
                             }
                           }
                         },
                         "commands": {
                            "0-enableSSM" : {
                              "command" : "powershell.exe -Command \"Set-Service -Name AmazonSSMAgent -StartupType Automatic\" ",
                              "waitAfterCompletion" : "0"
                            },
                            "1-restartSSM": {
                              "command" : "powershell.exe -Command \"Restart-Service AmazonSSMAgent \"",
                              "waitAfterCompletion" : "30"
                            }
                         }
                    }
                }
            }
        }
    },
    "Outputs": {
        "LogsURL": {
          "Value": {"Fn::Join": ["", [ "https://console.aws.amazon.com/cloudwatch/home?region=", {"Ref": "AWS::Region"}, "#logStream:group=", {"Ref": "DeploymentLogs"} ] ]},
          "Description": "Deployment Logs"
        },
        "VPCId" : {
          "Value" :  {"Ref" : "VPCId"},
          "Description" : "VPC ID"
        },
        "DeploymentBucket" : {
          "Value" :  {"Ref" : "DeploymentBucket"},
          "Description" : "Deployment S3 bucket"
        },
        "SecurityGroup" : {
          "Value" :  {"Ref" : "SecurityGroupId"},
          "Description" : "Security group"
        }
    }
}
