Parameters:
  EEKeyPair:
    Type: AWS::EC2::KeyPair::KeyName
    Default: EEKeyPair
    Description: Event Engine Name of the EC2 KeyPair generated for the Team
  LatestAMI:
    Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
    Default: /aws/service/ami-windows-latest/Windows_Server-2019-English-Full-Base
    Description: Latest AMI from windows
Resources:
  CodeDeployServiceRole897ED2CE:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action: sts:AssumeRole
            Effect: Allow
            Principal:
              Service:
                Fn::Join:
                  - ""
                  - - codedeploy.
                    - Ref: AWS::Region
                    - "."
                    - Ref: AWS::URLSuffix
        Version: "2012-10-17"
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole
      Path: /
    Metadata:
      aws:cdk:path: Module5/CodeDeployServiceRole/Resource
  awscodestarservicerole60377864:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action: sts:AssumeRole
            Effect: Allow
            Principal:
              Service: codestar.amazonaws.com
        Version: "2012-10-17"
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/service-role/AWSCodeStarServiceRole
      Path: /service-role/
    Metadata:
      aws:cdk:path: Module5/awscodestarservicerole/Resource
  awselasticbeanstalkserviceroleD8411EF4:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action: sts:AssumeRole
            Condition:
              StringEquals:
                sts:ExternalId: elasticbeanstalk
            Effect: Allow
            Principal:
              Service: elasticbeanstalk.amazonaws.com
        Version: "2012-10-17"
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/service-role/AWSElasticBeanstalkEnhancedHealth
        - arn:aws:iam::aws:policy/service-role/AWSElasticBeanstalkService
    Metadata:
      aws:cdk:path: Module5/awselasticbeanstalkservicerole/Resource
  CreateGitCredsRole385E94AC:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action: sts:AssumeRole
            Effect: Allow
            Principal:
              Service: lambda.amazonaws.com
        Version: "2012-10-17"
      Path: /
      Policies:
        - PolicyDocument:
            Statement:
              - Action:
                  - iam:CreateServiceSpecificCredential
                  - iam:ListServiceSpecificCredentials
                  - iam:DeleteServiceSpecificCredential
                Effect: Allow
                Resource: "*"
              - Action:
                  - logs:CreateLogGroup
                  - logs:CreateLogStream
                  - logs:PutLogEvents
                Effect: Allow
                Resource: arn:aws:logs:*:*:*
            Version: "2012-10-17"
          PolicyName: root
    Metadata:
      aws:cdk:path: Module5/CreateGitCredsRole/Resource
  DevAxNetworkVPC049CF20B:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.20.0.0/16
      EnableDnsHostnames: true
      EnableDnsSupport: true
      InstanceTenancy: default
      Tags:
        - Key: Name
          Value: Module5/DevAxNetworkVPC
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/Resource
  DevAxNetworkVPCpublicSubnet1Subnet18336BFA:
    Type: AWS::EC2::Subnet
    Properties:
      CidrBlock: 10.20.0.0/24
      VpcId:
        Ref: DevAxNetworkVPC049CF20B
      AvailabilityZone:
        Fn::Select:
          - 0
          - Fn::GetAZs: ""
      MapPublicIpOnLaunch: true
      Tags:
        - Key: aws-cdk:subnet-name
          Value: public
        - Key: aws-cdk:subnet-type
          Value: Public
        - Key: Name
          Value: Module5/DevAxNetworkVPC/publicSubnet1
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/publicSubnet1/Subnet
  DevAxNetworkVPCpublicSubnet1RouteTable397546CD:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId:
        Ref: DevAxNetworkVPC049CF20B
      Tags:
        - Key: Name
          Value: Module5/DevAxNetworkVPC/publicSubnet1
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/publicSubnet1/RouteTable
  DevAxNetworkVPCpublicSubnet1RouteTableAssociation32F54607:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      RouteTableId:
        Ref: DevAxNetworkVPCpublicSubnet1RouteTable397546CD
      SubnetId:
        Ref: DevAxNetworkVPCpublicSubnet1Subnet18336BFA
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/publicSubnet1/RouteTableAssociation
  DevAxNetworkVPCpublicSubnet1DefaultRoute088828A0:
    Type: AWS::EC2::Route
    Properties:
      RouteTableId:
        Ref: DevAxNetworkVPCpublicSubnet1RouteTable397546CD
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId:
        Ref: DevAxNetworkVPCIGW3AED8105
    DependsOn:
      - DevAxNetworkVPCVPCGWBDEEED8F
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/publicSubnet1/DefaultRoute
  DevAxNetworkVPCpublicSubnet1EIP241549E0:
    Type: AWS::EC2::EIP
    Properties:
      Domain: vpc
      Tags:
        - Key: Name
          Value: Module5/DevAxNetworkVPC/publicSubnet1
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/publicSubnet1/EIP
  DevAxNetworkVPCpublicSubnet1NATGateway8B09B209:
    Type: AWS::EC2::NatGateway
    Properties:
      AllocationId:
        Fn::GetAtt:
          - DevAxNetworkVPCpublicSubnet1EIP241549E0
          - AllocationId
      SubnetId:
        Ref: DevAxNetworkVPCpublicSubnet1Subnet18336BFA
      Tags:
        - Key: Name
          Value: Module5/DevAxNetworkVPC/publicSubnet1
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/publicSubnet1/NATGateway
  DevAxNetworkVPCpublicSubnet2Subnet0FE75CE7:
    Type: AWS::EC2::Subnet
    Properties:
      CidrBlock: 10.20.1.0/24
      VpcId:
        Ref: DevAxNetworkVPC049CF20B
      AvailabilityZone:
        Fn::Select:
          - 1
          - Fn::GetAZs: ""
      MapPublicIpOnLaunch: true
      Tags:
        - Key: aws-cdk:subnet-name
          Value: public
        - Key: aws-cdk:subnet-type
          Value: Public
        - Key: Name
          Value: Module5/DevAxNetworkVPC/publicSubnet2
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/publicSubnet2/Subnet
  DevAxNetworkVPCpublicSubnet2RouteTable697DCAB0:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId:
        Ref: DevAxNetworkVPC049CF20B
      Tags:
        - Key: Name
          Value: Module5/DevAxNetworkVPC/publicSubnet2
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/publicSubnet2/RouteTable
  DevAxNetworkVPCpublicSubnet2RouteTableAssociation88AA6DF8:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      RouteTableId:
        Ref: DevAxNetworkVPCpublicSubnet2RouteTable697DCAB0
      SubnetId:
        Ref: DevAxNetworkVPCpublicSubnet2Subnet0FE75CE7
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/publicSubnet2/RouteTableAssociation
  DevAxNetworkVPCpublicSubnet2DefaultRoute4C133366:
    Type: AWS::EC2::Route
    Properties:
      RouteTableId:
        Ref: DevAxNetworkVPCpublicSubnet2RouteTable697DCAB0
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId:
        Ref: DevAxNetworkVPCIGW3AED8105
    DependsOn:
      - DevAxNetworkVPCVPCGWBDEEED8F
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/publicSubnet2/DefaultRoute
  DevAxNetworkVPCpublicSubnet2EIP2C72517D:
    Type: AWS::EC2::EIP
    Properties:
      Domain: vpc
      Tags:
        - Key: Name
          Value: Module5/DevAxNetworkVPC/publicSubnet2
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/publicSubnet2/EIP
  DevAxNetworkVPCpublicSubnet2NATGateway63D3A4D0:
    Type: AWS::EC2::NatGateway
    Properties:
      AllocationId:
        Fn::GetAtt:
          - DevAxNetworkVPCpublicSubnet2EIP2C72517D
          - AllocationId
      SubnetId:
        Ref: DevAxNetworkVPCpublicSubnet2Subnet0FE75CE7
      Tags:
        - Key: Name
          Value: Module5/DevAxNetworkVPC/publicSubnet2
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/publicSubnet2/NATGateway
  DevAxNetworkVPCprivateSubnet1SubnetF1C6C29A:
    Type: AWS::EC2::Subnet
    Properties:
      CidrBlock: 10.20.2.0/24
      VpcId:
        Ref: DevAxNetworkVPC049CF20B
      AvailabilityZone:
        Fn::Select:
          - 0
          - Fn::GetAZs: ""
      MapPublicIpOnLaunch: false
      Tags:
        - Key: aws-cdk:subnet-name
          Value: private
        - Key: aws-cdk:subnet-type
          Value: Private
        - Key: Name
          Value: Module5/DevAxNetworkVPC/privateSubnet1
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/privateSubnet1/Subnet
  DevAxNetworkVPCprivateSubnet1RouteTableF757820F:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId:
        Ref: DevAxNetworkVPC049CF20B
      Tags:
        - Key: Name
          Value: Module5/DevAxNetworkVPC/privateSubnet1
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/privateSubnet1/RouteTable
  DevAxNetworkVPCprivateSubnet1RouteTableAssociation94A46865:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      RouteTableId:
        Ref: DevAxNetworkVPCprivateSubnet1RouteTableF757820F
      SubnetId:
        Ref: DevAxNetworkVPCprivateSubnet1SubnetF1C6C29A
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/privateSubnet1/RouteTableAssociation
  DevAxNetworkVPCprivateSubnet1DefaultRoute07EFC529:
    Type: AWS::EC2::Route
    Properties:
      RouteTableId:
        Ref: DevAxNetworkVPCprivateSubnet1RouteTableF757820F
      DestinationCidrBlock: 0.0.0.0/0
      NatGatewayId:
        Ref: DevAxNetworkVPCpublicSubnet1NATGateway8B09B209
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/privateSubnet1/DefaultRoute
  DevAxNetworkVPCprivateSubnet2SubnetD148A816:
    Type: AWS::EC2::Subnet
    Properties:
      CidrBlock: 10.20.3.0/24
      VpcId:
        Ref: DevAxNetworkVPC049CF20B
      AvailabilityZone:
        Fn::Select:
          - 1
          - Fn::GetAZs: ""
      MapPublicIpOnLaunch: false
      Tags:
        - Key: aws-cdk:subnet-name
          Value: private
        - Key: aws-cdk:subnet-type
          Value: Private
        - Key: Name
          Value: Module5/DevAxNetworkVPC/privateSubnet2
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/privateSubnet2/Subnet
  DevAxNetworkVPCprivateSubnet2RouteTable81AEA059:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId:
        Ref: DevAxNetworkVPC049CF20B
      Tags:
        - Key: Name
          Value: Module5/DevAxNetworkVPC/privateSubnet2
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/privateSubnet2/RouteTable
  DevAxNetworkVPCprivateSubnet2RouteTableAssociation973AEB51:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      RouteTableId:
        Ref: DevAxNetworkVPCprivateSubnet2RouteTable81AEA059
      SubnetId:
        Ref: DevAxNetworkVPCprivateSubnet2SubnetD148A816
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/privateSubnet2/RouteTableAssociation
  DevAxNetworkVPCprivateSubnet2DefaultRouteE9B8CAFD:
    Type: AWS::EC2::Route
    Properties:
      RouteTableId:
        Ref: DevAxNetworkVPCprivateSubnet2RouteTable81AEA059
      DestinationCidrBlock: 0.0.0.0/0
      NatGatewayId:
        Ref: DevAxNetworkVPCpublicSubnet2NATGateway63D3A4D0
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/privateSubnet2/DefaultRoute
  DevAxNetworkVPCIGW3AED8105:
    Type: AWS::EC2::InternetGateway
    Properties:
      Tags:
        - Key: Name
          Value: Module5/DevAxNetworkVPC
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/IGW
  DevAxNetworkVPCVPCGWBDEEED8F:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      VpcId:
        Ref: DevAxNetworkVPC049CF20B
      InternetGatewayId:
        Ref: DevAxNetworkVPCIGW3AED8105
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkVPC/VPCGW
  DevAxNetworkSGF6BD3961:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Module5/DevAxNetworkSG
      GroupName: DBSecurityGroup
      SecurityGroupEgress:
        - CidrIp: 0.0.0.0/0
          Description: Allow all outbound traffic by default
          IpProtocol: "-1"
      SecurityGroupIngress:
        - CidrIp: 0.0.0.0/0
          Description: from 0.0.0.0/0:3306
          FromPort: 3306
          IpProtocol: tcp
          ToPort: 3306
      VpcId:
        Ref: DevAxNetworkVPC049CF20B
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkSG/Resource
  DevAxNetworkSGfromModule5DevAxWindowsSecurityGroup62C3333C3306B9E7FB57:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      IpProtocol: tcp
      Description: WorkshopHost to DB over mysql
      FromPort: 3306
      GroupId:
        Fn::GetAtt:
          - DevAxNetworkSGF6BD3961
          - GroupId
      SourceSecurityGroupId:
        Fn::GetAtt:
          - DevAxWindowsSecurityGroupDE999860
          - GroupId
      ToPort: 3306
    Metadata:
      aws:cdk:path: Module5/DevAxNetworkSG/from Module5DevAxWindowsSecurityGroup62C3333C:3306
  DBinstanceSubnetGroupA78F1F9F:
    Type: AWS::RDS::DBSubnetGroup
    Properties:
      DBSubnetGroupDescription: Subnet group for DBinstance database
      SubnetIds:
        - Ref: DevAxNetworkVPCprivateSubnet1SubnetF1C6C29A
        - Ref: DevAxNetworkVPCprivateSubnet2SubnetD148A816
    Metadata:
      aws:cdk:path: Module5/DBinstance/SubnetGroup/Default
  DBinstanceA5CF359B:
    Type: AWS::RDS::DBInstance
    Properties:
      DBInstanceClass: db.t2.small
      AllocatedStorage: "5"
      AutoMinorVersionUpgrade: false
      BackupRetentionPeriod: 3
      CopyTagsToSnapshot: true
      DBName: travelbuddy
      DBSubnetGroupName:
        Ref: DBinstanceSubnetGroupA78F1F9F
      DeletionProtection: false
      Engine: mysql
      EngineVersion: "8.0"
      MasterUsername: root
      MasterUserPassword: labpassword
      MultiAZ: false
      Port: "3306"
      PubliclyAccessible: false
      StorageEncrypted: true
      StorageType: gp2
      VPCSecurityGroups:
        - Fn::GetAtt:
            - DevAxNetworkSGF6BD3961
            - GroupId
    UpdateReplacePolicy: Snapshot
    Metadata:
      aws:cdk:path: Module5/DBinstance/Resource
  AWSStudent3111CB37:
    Type: AWS::IAM::User
    Properties:
      ManagedPolicyArns:
        - Fn::Join:
            - ""
            - - "arn:"
              - Ref: AWS::Partition
              - :iam::aws:policy/AWSCodeCommitPowerUser
      UserName: awsstudent
    Metadata:
      aws:cdk:path: Module5/AWSStudent/Resource
  DevAxWindowsSecurityGroupDE999860:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Module5/DevAxWindowsSecurityGroup
      GroupName: WorkspaceSecurityGroup
      SecurityGroupEgress:
        - CidrIp: 0.0.0.0/0
          Description: Allow all outbound traffic by default
          IpProtocol: "-1"
      SecurityGroupIngress:
        - CidrIp: 0.0.0.0/0
          Description: from 0.0.0.0/0:3389
          FromPort: 3389
          IpProtocol: tcp
          ToPort: 3389
      VpcId:
        Ref: DevAxNetworkVPC049CF20B
    Metadata:
      aws:cdk:path: Module5/DevAxWindowsSecurityGroup/Resource
  DevAxWindowsHost:
    Type: AWS::EC2::Instance
    Properties:
      ImageId:
        Ref: LatestAMI
      InstanceType: m5.xlarge
      KeyName:
        Ref: EEKeyPair
      NetworkInterfaces:
        - AssociatePublicIpAddress: true
          DeviceIndex: "0"
          GroupSet:
            - Fn::GetAtt:
                - DevAxWindowsSecurityGroupDE999860
                - GroupId
          SubnetId:
            Ref: DevAxNetworkVPCpublicSubnet1Subnet18336BFA
      SourceDestCheck: true
      Tags:
        - Key: Name
          Value: DevAxWindowsHost
      UserData:
        Fn::Base64:
          Fn::Sub: >-
            <script>
                        cfn-init.exe -v -s ${AWS::StackId} -r DevAxWindowsHost --configsets ascending --region ${AWS::Region}
                        </script>
    CreationPolicy:
      ResourceSignal:
        Count: 1
        Timeout: PT60M
    Metadata:
      AWS::CloudFormation::Init:
        configSets:
          ascending:
            - setup
            - install
            - finalise
        setup:
          files:
            C:\setup\setenvironment.ps1:
              content: >-
                # Set execution policy and install chocolatey

                Set-ExecutionPolicy Bypass -Scope Process -Force

                [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072

                iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))


                # Reload profile

                $env:ChocolateyInstall = Convert-Path "$((Get-Command choco).Path)\..\.."   

                Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"


                # Install Git

                choco install git -y --params="'/GitAndUnixToolsOnPath /NoAutoCrlf'"


                # Install AdoptOpenJDK jdk8 hotspot 8.262.10 https://chocolatey.org/packages/corretto8jdk

                choco install corretto8jdk -y 

                refreshenv


                # Install IntelliJ https://chocolatey.org/packages/intellijidea-community

                choco install intellijidea-community -y


                # Install eclipse https://chocolatey.org/packages/eclipse

                choco install eclipse --version=4.15 -y --params "'/InstallationPath=C:\eclipse'"

                & "c:\\setup\\eclipseinstall.ps1"


                # Install Apache Maven https://chocolatey.org/packages/maven

                choco install maven -y


                # Install Tomcat https://chocolatey.org/packages/tomcat

                choco install tomcat -y


                # Install Python 3 https://chocolatey.org/packages/python3

                choco install python3 -y

                refreshenv


                # Install AWS Cli 2 https://chocolatey.org/packages/awscli

                choco install awscli -y


                # Install Google Chrome https://chocolatey.org/packages/googlechrome

                choco install googlechrome -y --ignore-checksums


                # Install Elastic Beanstalk CLI

                pip install awsebcli --upgrade


                # Install MySQL Client https://chocolatey.org/packages/mysql-cli

                choco install mysql-cli


                # Move tomcat server to C:\ProgramData\Tomcat9

                $tomcatPath = Get-ChildItem -Path C:\ProgramData\chocolatey\lib\Tomcat\tools -Directory | Select-Object -First 1

                Get-ChildItem -Path $tomcatPath.FullName -Recurse | Move-Item -Destination C:\ProgramData\Tomcat9\


                # Clear desktop

                $wshShell = New-Object -ComObject "WScript.Shell"

                Get-ChildItem -Path  $wshShell.SpecialFolders.Item("AllUsersDesktop") -Recurse -ErrorAction SilentlyContinue | foreach { Remove-Item -Path $_.FullName }

                Get-ChildItem -Path  $wshShell.SpecialFolders.Item("Desktop") -Recurse -ErrorAction SilentlyContinue | foreach { Remove-Item -Path $_.FullName }


                # Create shortcuts

                $wshShell = New-Object -ComObject "WScript.Shell"

                $urlShortcut = $wshShell.CreateShortcut(
                  (Join-Path $wshShell.SpecialFolders.Item("AllUsersDesktop") "Dashboard.url")
                )

                $urlShortcut.TargetPath = "https://dashboard.eventengine.run/login"

                $urlShortcut.Save()


                $wshShell = New-Object -ComObject "WScript.Shell"

                $urlShortcut = $wshShell.CreateShortcut(
                  (Join-Path $wshShell.SpecialFolders.Item("AllUsersDesktop") "Workshop.url")
                )

                $urlShortcut.TargetPath = "https://workshops.devax.academy/monoliths-to-microservices/"

                $urlShortcut.Save()
            C:\setup\eclipseinstall.ps1:
              content: >
                $eclipseBasePath = "C:\eclipse"

                $eclipseVer = Get-ChildItem -Path $eclipseBasePath -Force -Recurse | Select-Object -First 1

                $eclipseDir = [IO.Path]::Combine($eclipseBasePath, $eclipseVer, 'eclipse\eclipse')


                # Install AWS Toolkit for eclipse

                & $eclipseDir -nosplash -application org.eclipse.equinox.p2.director -repository https://aws.amazon.com/eclipse -installIU com.amazonaws.eclipse.core.feature.feature.group | Out-Null

                & $eclipseDir -nosplash -application org.eclipse.equinox.p2.director -repository https://aws.amazon.com/eclipse -installIU com.amazonaws.eclipse.sdk.ui.feature.feature.group | Out-Null

                & $eclipseDir -nosplash -application org.eclipse.equinox.p2.director -repository https://aws.amazon.com/eclipse -installIU com.amazonaws.eclipse.ec2.feature.feature.group | Out-Null

                & $eclipseDir -nosplash -application org.eclipse.equinox.p2.director -repository https://aws.amazon.com/eclipse -installIU com.amazonaws.eclipse.dynamodb.feature.feature.group | Out-Null

                & $eclipseDir -nosplash -application org.eclipse.equinox.p2.director -repository https://aws.amazon.com/eclipse -installIU com.amazonaws.eclipse.identitymanagement.feature.feature.group | Out-Null

                & $eclipseDir -nosplash -application org.eclipse.equinox.p2.director -repository https://aws.amazon.com/eclipse -installIU com.amazonaws.eclipse.cloudformation.feature.feature.group | Out-Null

                & $eclipseDir -nosplash -application org.eclipse.equinox.p2.director -repository https://aws.amazon.com/eclipse -installIU com.amazonaws.eclipse.codecommit.feature.feature.group | Out-Null

                & $eclipseDir -nosplash -application org.eclipse.equinox.p2.director -repository https://aws.amazon.com/eclipse -installIU com.amazonaws.eclipse.codedeploy.feature.feature.group | Out-Null

                & $eclipseDir -nosplash -application org.eclipse.equinox.p2.director -repository https://aws.amazon.com/eclipse -installIU com.amazonaws.eclipse.codestar.feature.feature.group | Out-Null

                & $eclipseDir -nosplash -application org.eclipse.equinox.p2.director -repository https://aws.amazon.com/eclipse -installIU com.amazonaws.eclipse.elasticbeanstalk.feature.feature.group | Out-Null

                & $eclipseDir -nosplash -application org.eclipse.equinox.p2.director -repository https://aws.amazon.com/eclipse -installIU com.amazonaws.eclipse.lambda.feature.feature.group | Out-Null

                & $eclipseDir -nosplash -application org.eclipse.equinox.p2.director -repository https://aws.amazon.com/eclipse -installIU com.amazonaws.eclipse.opsworks.feature.feature.group | Out-Null

                & $eclipseDir -nosplash -application org.eclipse.equinox.p2.director -repository https://aws.amazon.com/eclipse -installIU com.amazonaws.eclipse.rds.feature.feature.group | Out-Null
            C:\setup\DB.sql:
              content: >
                #

                # Lab 1 - DB Seed Script

                #


                use travelbuddy;

                DROP TABLE IF EXISTS `flightspecial`;

                CREATE TABLE `flightspecial` (
                  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
                  `header` varchar(255) NOT NULL DEFAULT '',
                  `body` varchar(255) DEFAULT NULL,
                  `origin` varchar(255) DEFAULT NULL,
                  `originCode` varchar(6) DEFAULT NULL,
                  `destination` varchar(255) DEFAULT NULL,
                  `destinationCode` varchar(6) DEFAULT NULL,
                  `cost` int(11) NOT NULL,
                  `expiryDate` bigint(16) NOT NULL,
                  PRIMARY KEY (`id`)
                ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;


                INSERT INTO `flightspecial`

                (`expiryDate`, `cost`, `header`, `body`, `origin`, `originCode`, `destination`, `destinationCode`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 200),

                'London to Prague', 'Jewel of the East', 'London', 'LHR', 'Paris', 'CDG'

                );


                INSERT INTO `flightspecial`

                (`expiryDate`, `cost`, `header`, `body`, `origin`, `originCode`, `destination`, `destinationCode`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 200),

                'Paris to London', 'Weekend getaway!', 'Origin', 'ORG', 'Destination', 'DST'

                );


                INSERT INTO `flightspecial`

                (`expiryDate`, `cost`, `header`, `body`, `origin`, `originCode`, `destination`, `destinationCode`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 200),

                'Dubai to Cairo', 'Middle East adventure', 'Origin', 'ORG', 'Destination', 'DST'

                );


                INSERT INTO `flightspecial`

                (`expiryDate`, `cost`, `header`, `body`, `origin`, `originCode`, `destination`, `destinationCode`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 500),

                'Melbourne to Hawaii', 'Escape to the sun this winter', 'Origin', 'ORG', 'Destination', 'DST'

                );


                INSERT INTO `flightspecial`

                (`expiryDate`, `cost`, `header`, `body`, `origin`, `originCode`, `destination`, `destinationCode`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 200),

                'Buenos Aires to Rio', 'Time to carnivale!', 'Origin', 'ORG', 'Destination', 'DST'

                );


                INSERT INTO `flightspecial`

                (`expiryDate`, `cost`, `header`, `body`, `origin`, `originCode`, `destination`, `destinationCode`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 500),

                'Sydney to Rome', 'An Italian classic', 'Origin', 'ORG', 'Destination', 'DST'

                );


                INSERT INTO `flightspecial`

                (`expiryDate`, `cost`, `header`, `body`, `origin`, `originCode`, `destination`, `destinationCode`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 500),

                'Melbourne to Sydney', 'Well trodden path', 'Origin', 'ORG', 'Destination', 'DST'

                );


                INSERT INTO `flightspecial`

                (`expiryDate`, `cost`, `header`, `body`, `origin`, `originCode`, `destination`, `destinationCode`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 500),

                'Hong Kong to Kuala Lumpur', 'Hop step and a jump', 'Origin', 'ORG', 'Destination', 'DST'

                );


                INSERT INTO `flightspecial`

                (`expiryDate`, `cost`, `header`, `body`, `origin`, `originCode`, `destination`, `destinationCode`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 500),

                'Lisbon to Madrid', 'Spanish adventure', 'Origin', 'ORG', 'Destination', 'DST'

                );


                INSERT INTO `flightspecial`

                (`expiryDate`, `cost`, `header`, `body`, `origin`, `originCode`, `destination`, `destinationCode`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 500),

                'Aswan to Cairo', 'An experience of a lifetime', 'Origin', 'ORG', 'Destination', 'DST'

                );


                INSERT INTO `flightspecial`

                (`expiryDate`, `cost`, `header`, `body`, `origin`, `originCode`, `destination`, `destinationCode`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 500),

                'New York to London', 'Trans-Atlantic', 'Origin', 'ORG', 'Destination', 'DST'

                );


                #---------------------------------------------------------------------------------------------------------------------

                #---------------------------------------------------------------------------------------------------------------------

                #---------------------------------------------------------------------------------------------------------------------

                #---------------------------------------------------------------------------------------------------------------------

                #---------------------------------------------------------------------------------------------------------------------


                DROP TABLE IF EXISTS `hotelspecial`;

                CREATE TABLE `hotelspecial` (
                  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
                  `hotel` varchar(255) NOT NULL DEFAULT '',
                  `description` varchar(255) DEFAULT NULL,
                  `location` varchar(255) DEFAULT NULL,
                  `cost` int(11) NOT NULL,
                  `expiryDate` bigint(16) NOT NULL,
                  PRIMARY KEY (`id`)
                ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;


                INSERT INTO `hotelspecial`

                (`expiryDate`, `cost`, `hotel`, `description`, `location`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 1000),

                'Sommerset Hotel', 'Minimum stay 3 nights', 'Sydney'

                );


                INSERT INTO `hotelspecial`

                (`expiryDate`, `cost`, `hotel`, `description`, `location`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 1000),

                'Freedmom Apartments', 'Pets allowed!', 'Sydney'

                );


                INSERT INTO `hotelspecial`

                (`expiryDate`, `cost`, `hotel`, `description`, `location`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 1000),

                'Studio City', 'Minimum stay one week', 'Los Angeles'

                );


                INSERT INTO `hotelspecial`

                (`expiryDate`, `cost`, `hotel`, `description`, `location`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 1000),

                'Le Fleur Hotel', 'Not available weekends', 'Los Angeles'

                );


                INSERT INTO `hotelspecial`

                (`expiryDate`, `cost`, `hotel`, `description`, `location`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 1000),

                'Classic Hotel', 'Includes breakfast', 'Dallas'

                );


                INSERT INTO `hotelspecial`

                (`expiryDate`, `cost`, `hotel`, `description`, `location`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 1000),

                'Groundhog Suites', 'Internet access included', 'Florida'

                );


                INSERT INTO `hotelspecial`

                (`expiryDate`, `cost`, `hotel`, `description`, `location`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 1000),

                'Sophmore Suites', 'Maximum 2 people per room', 'London'

                );


                INSERT INTO `hotelspecial`

                (`expiryDate`, `cost`, `hotel`, `description`, `location`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 1000),

                'Hotel Sandra', 'Minimum stay two nights', 'Cairo'

                );


                INSERT INTO `hotelspecial`

                (`expiryDate`, `cost`, `hotel`, `description`, `location`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 1000),

                'Apartamentos de Nestor', 'Pool and spa access included', 'Madrid'

                );


                INSERT INTO `hotelspecial`

                (`expiryDate`, `cost`, `hotel`, `description`, `location`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 1000),

                'Kangaroo Hotel', 'Maximum 2 people per room', 'Manchester'

                );


                INSERT INTO `hotelspecial`

                (`expiryDate`, `cost`, `hotel`, `description`, `location`)

                VALUES (

                (SELECT (UNIX_TIMESTAMP() * 1000)) + 79200 + (RAND() * 20000000),

                (50 + RAND() * 1000),

                'EasyStay Apartments', 'Minimum stay one week', 'Melbourne'

                );
        install:
          commands:
            runsetup:
              command: powershell.exe -ExecutionPolicy Unrestricted C:\setup\setenvironment.ps1
              waitAfterCompletion: "0"
            seed:
              command:
                Fn::Sub:
                  - C:\ProgramData\chocolatey\bin\mysql -h ${endpoint} -u ${user} -p${password} -P 3306 < C:\setup\DB.sql
                  - endpoint:
                      Fn::GetAtt:
                        - DBinstanceA5CF359B
                        - Endpoint.Address
                    user: root
                    password: labpassword
              waitAfterCompletion: "0"
        finalise:
          commands:
            cleanup:
              command: rmdir C:\setup /s /q
              waitAfterCompletion: "0"
            signal:
              command:
                Fn::Sub: cfn-signal.exe -e %ERRORLEVEL% --resource DevAxWindowsHost --stack ${AWS::StackName} --region ${AWS::Region}
  EC2InstanceKCLEIP:
    Type: AWS::EC2::EIP
    Properties:
      Domain: vpc
    Metadata:
      aws:cdk:path: Module5/EC2InstanceKCLEIP
  LambdaKinesisToSQSRole62EAD38E:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action: sts:AssumeRole
            Effect: Allow
            Principal:
              Service: lambda.amazonaws.com
        Version: "2012-10-17"
      Policies:
        - PolicyDocument:
            Statement:
              - Action:
                  - sns:*
                  - sqs:*
                  - kinesis:*
                  - cloudwatch:*
                  - logs:*
                  - xray:*
                Effect: Allow
                Resource: "*"
            Version: "2012-10-17"
          PolicyName: root
      RoleName: LambdaKinesisToSQSRole
    Metadata:
      aws:cdk:path: Module5/LambdaKinesisToSQSRole/Resource
  elasticSearchKinesisStream8F1D7EB0:
    Type: AWS::Kinesis::Stream
    Properties:
      ShardCount: 2
      Name: iDevelopElasticSearchKinesisStream
      RetentionPeriodHours: 24
      StreamEncryption:
        Fn::If:
          - AwsCdkKinesisEncryptedStreamsUnsupportedRegions
          - Ref: AWS::NoValue
          - EncryptionType: KMS
            KeyId: alias/aws/kinesis
    Metadata:
      aws:cdk:path: Module5/elasticSearchKinesisStream/Resource
  elasticSearchDomain:
    Type: AWS::Elasticsearch::Domain
    Properties:
      AccessPolicies:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Principal:
              AWS:
                Fn::Join:
                  - ""
                  - - "arn:aws:iam::"
                    - Ref: AWS::AccountId
                    - :root
            Action:
              - es:*
            Resource:
              Fn::Join:
                - ""
                - - "arn:aws:es:"
                  - Ref: AWS::Region
                  - ":"
                  - Ref: AWS::AccountId
                  - :domain/idevelop/*
          - Effect: Allow
            Principal:
              AWS: "*"
            Action:
              - es:*
            Resource:
              Fn::Join:
                - ""
                - - "arn:aws:es:"
                  - Ref: AWS::Region
                  - ":"
                  - Ref: AWS::AccountId
                  - :domain/idevelop/*
            Condition:
              IpAddress:
                aws:SourceIp:
                  Ref: EC2InstanceKCLEIP
      DomainName: idevelop
      EBSOptions:
        EBSEnabled: false
      ElasticsearchClusterConfig:
        InstanceType: m3.medium.elasticsearch
      ElasticsearchVersion: "2.3"
    Metadata:
      aws:cdk:path: Module5/elasticSearchDomain
  kinesisStreamDrawingData53AF8C0E:
    Type: AWS::Kinesis::Stream
    Properties:
      ShardCount: 1
      Name: iDevelopDrawingData
      RetentionPeriodHours: 24
      StreamEncryption:
        Fn::If:
          - AwsCdkKinesisEncryptedStreamsUnsupportedRegions
          - Ref: AWS::NoValue
          - EncryptionType: KMS
            KeyId: alias/aws/kinesis
    Metadata:
      aws:cdk:path: Module5/kinesisStreamDrawingData/Resource
  idevelopDrawQueueFIFOB708BF02:
    Type: AWS::SQS::Queue
    Properties:
      ContentBasedDeduplication: true
      FifoQueue: true
      QueueName: idevelop_drawqueue.fifo
    Metadata:
      aws:cdk:path: Module5/idevelopDrawQueueFIFO/Resource
  idevelopDrawQueueStandard12D32FE88:
    Type: AWS::SQS::Queue
    Properties:
      QueueName: idevelop_drawqueue_1
    Metadata:
      aws:cdk:path: Module5/idevelopDrawQueueStandard1/Resource
  idevelopDrawQueueStandard1Policy61DFDD30:
    Type: AWS::SQS::QueuePolicy
    Properties:
      PolicyDocument:
        Statement:
          - Action: sqs:SendMessage
            Condition:
              ArnEquals:
                aws:SourceArn:
                  Ref: idevelopDrawTopicF93DE7CF
            Effect: Allow
            Principal:
              Service: sns.amazonaws.com
            Resource:
              Fn::GetAtt:
                - idevelopDrawQueueStandard12D32FE88
                - Arn
        Version: "2012-10-17"
      Queues:
        - Ref: idevelopDrawQueueStandard12D32FE88
    Metadata:
      aws:cdk:path: Module5/idevelopDrawQueueStandard1/Policy/Resource
  idevelopDrawQueueStandard1Module5idevelopDrawTopicC6299515A0CC6267:
    Type: AWS::SNS::Subscription
    Properties:
      Protocol: sqs
      TopicArn:
        Ref: idevelopDrawTopicF93DE7CF
      Endpoint:
        Fn::GetAtt:
          - idevelopDrawQueueStandard12D32FE88
          - Arn
    Metadata:
      aws:cdk:path: Module5/idevelopDrawQueueStandard1/Module5idevelopDrawTopicC6299515/Resource
  idevelopDrawQueueStandard2368FBC93:
    Type: AWS::SQS::Queue
    Properties:
      QueueName: idevelop_drawqueue_2
    Metadata:
      aws:cdk:path: Module5/idevelopDrawQueueStandard2/Resource
  idevelopDrawQueueStandard2Policy5020DC0D:
    Type: AWS::SQS::QueuePolicy
    Properties:
      PolicyDocument:
        Statement:
          - Action: sqs:SendMessage
            Condition:
              ArnEquals:
                aws:SourceArn:
                  Ref: idevelopDrawTopicF93DE7CF
            Effect: Allow
            Principal:
              Service: sns.amazonaws.com
            Resource:
              Fn::GetAtt:
                - idevelopDrawQueueStandard2368FBC93
                - Arn
        Version: "2012-10-17"
      Queues:
        - Ref: idevelopDrawQueueStandard2368FBC93
    Metadata:
      aws:cdk:path: Module5/idevelopDrawQueueStandard2/Policy/Resource
  idevelopDrawQueueStandard2Module5idevelopDrawTopicC62995152EEE5190:
    Type: AWS::SNS::Subscription
    Properties:
      Protocol: sqs
      TopicArn:
        Ref: idevelopDrawTopicF93DE7CF
      Endpoint:
        Fn::GetAtt:
          - idevelopDrawQueueStandard2368FBC93
          - Arn
    Metadata:
      aws:cdk:path: Module5/idevelopDrawQueueStandard2/Module5idevelopDrawTopicC6299515/Resource
  idevelopDrawQueueStandard3769393EA:
    Type: AWS::SQS::Queue
    Properties:
      QueueName: idevelop_drawqueue_3
    Metadata:
      aws:cdk:path: Module5/idevelopDrawQueueStandard3/Resource
  idevelopDrawQueueStandard3PolicyC274F6D3:
    Type: AWS::SQS::QueuePolicy
    Properties:
      PolicyDocument:
        Statement:
          - Action: sqs:SendMessage
            Condition:
              ArnEquals:
                aws:SourceArn:
                  Ref: idevelopDrawTopicF93DE7CF
            Effect: Allow
            Principal:
              Service: sns.amazonaws.com
            Resource:
              Fn::GetAtt:
                - idevelopDrawQueueStandard3769393EA
                - Arn
        Version: "2012-10-17"
      Queues:
        - Ref: idevelopDrawQueueStandard3769393EA
    Metadata:
      aws:cdk:path: Module5/idevelopDrawQueueStandard3/Policy/Resource
  idevelopDrawQueueStandard3Module5idevelopDrawTopicC62995159D09D12C:
    Type: AWS::SNS::Subscription
    Properties:
      Protocol: sqs
      TopicArn:
        Ref: idevelopDrawTopicF93DE7CF
      Endpoint:
        Fn::GetAtt:
          - idevelopDrawQueueStandard3769393EA
          - Arn
    Metadata:
      aws:cdk:path: Module5/idevelopDrawQueueStandard3/Module5idevelopDrawTopicC6299515/Resource
  CIPMessageDraw:
    Type: AWS::Cognito::IdentityPool
    Properties:
      AllowUnauthenticatedIdentities: true
      IdentityPoolName: iDevelop_Messaging
    Metadata:
      aws:cdk:path: Module5/CIPMessageDraw
  idevelopDrawTopicF93DE7CF:
    Type: AWS::SNS::Topic
    Properties:
      TopicName: iDevelopMessageDuplicator
    Metadata:
      aws:cdk:path: Module5/idevelopDrawTopic/Resource
  cognitoIAMUnauthenticatedRole399D1BE2:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action: sts:AssumeRoleWithWebIdentity
            Condition:
              StringEquals:
                cognito-identity.amazonaws.com:aud:
                  Ref: CIPMessageDraw
              ForAnyValue:StringLike:
                cognito-identity.amazonaws.com:amr: unauthenticated
            Effect: Allow
            Principal:
              Federated: cognito-identity.amazonaws.com
        Version: "2012-10-17"
      Path: /
      Policies:
        - PolicyDocument:
            Statement:
              - Action:
                  - mobileanalytics:PutEvents
                  - cognito-sync:*
                Effect: Allow
                Resource: "*"
            Version: "2012-10-17"
          PolicyName: standardCognito
        - PolicyDocument:
            Statement:
              - Action: sns:*
                Effect: Allow
                Resource:
                  Ref: idevelopDrawTopicF93DE7CF
            Version: "2012-10-17"
          PolicyName: snsPolicy
        - PolicyDocument:
            Statement:
              - Action:
                  - kinesis:PutRecord
                  - kinesis:PutRecords
                Effect: Allow
                Resource:
                  Fn::GetAtt:
                    - kinesisStreamDrawingData53AF8C0E
                    - Arn
            Version: "2012-10-17"
          PolicyName: kinesisPolicy
        - PolicyDocument:
            Statement:
              - Action: sqs:*
                Effect: Allow
                Resource:
                  - Fn::GetAtt:
                      - idevelopDrawQueueStandard12D32FE88
                      - Arn
                  - Fn::GetAtt:
                      - idevelopDrawQueueStandard2368FBC93
                      - Arn
                  - Fn::GetAtt:
                      - idevelopDrawQueueStandard3769393EA
                      - Arn
                  - Fn::GetAtt:
                      - idevelopDrawQueueFIFOB708BF02
                      - Arn
            Version: "2012-10-17"
          PolicyName: sqsPolicy
        - PolicyDocument:
            Statement:
              - Action: iot:Connect
                Effect: Allow
                Resource: "*"
              - Action:
                  - iot:Publish
                  - iot:Receive
                Effect: Allow
                Resource: arn:aws:iot:*:*:topic/idevelop/drawingdemo
              - Action: iot:Subscribe
                Effect: Allow
                Resource: arn:aws:iot:*:*:topicfilter/idevelop/drawingdemo
            Version: "2012-10-17"
          PolicyName: ioTPolicy
      RoleName: cognitoIAMUnauthenticatedRole
    Metadata:
      aws:cdk:path: Module5/cognitoIAMUnauthenticatedRole/Resource
  cognitoIAMAuthenticatedRoleDD1F6023:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action: sts:AssumeRoleWithWebIdentity
            Condition:
              StringEquals:
                cognito-identity.amazonaws.com:aud:
                  Ref: CIPMessageDraw
              ForAnyValue:StringLike:
                cognito-identity.amazonaws.com:amr: authenticated
            Effect: Allow
            Principal:
              Federated: cognito-identity.amazonaws.com
        Version: "2012-10-17"
      Path: /
      Policies:
        - PolicyDocument:
            Statement:
              - Action:
                  - mobileanalytics:PutEvents
                  - cognito-sync:*
                Effect: Allow
                Resource: "*"
            Version: "2012-10-17"
          PolicyName: standardCognito
      RoleName: cognitoIAMAuthenticatedRole
    Metadata:
      aws:cdk:path: Module5/cognitoIAMAuthenticatedRole/Resource
  CognitoRolesAttachment:
    Type: AWS::Cognito::IdentityPoolRoleAttachment
    Properties:
      IdentityPoolId:
        Ref: CIPMessageDraw
      Roles:
        authenticated:
          Fn::GetAtt:
            - cognitoIAMAuthenticatedRoleDD1F6023
            - Arn
        unauthenticated:
          Fn::GetAtt:
            - cognitoIAMUnauthenticatedRole399D1BE2
            - Arn
    Metadata:
      aws:cdk:path: Module5/CognitoRolesAttachment
  sqsPolicy:
    Type: AWS::SQS::QueuePolicy
    Properties:
      PolicyDocument:
        Statement:
          - Action:
              - sqs:SendMessage
              - sqs:ReceiveMessage
            Condition:
              StringEquals:
                aws:SourceAccount:
                  Ref: AWS::AccountId
            Effect: Allow
            Principal: "*"
            Resource: "*"
        Version: "2012-10-17"
      Queues:
        - Ref: idevelopDrawQueueStandard12D32FE88
        - Ref: idevelopDrawQueueStandard2368FBC93
        - Ref: idevelopDrawQueueStandard3769393EA
        - Ref: idevelopDrawQueueFIFOB708BF02
    DependsOn:
      - idevelopDrawQueueFIFOB708BF02
      - idevelopDrawQueueStandard1Module5idevelopDrawTopicC6299515A0CC6267
      - idevelopDrawQueueStandard1Policy61DFDD30
      - idevelopDrawQueueStandard12D32FE88
      - idevelopDrawQueueStandard2Module5idevelopDrawTopicC62995152EEE5190
      - idevelopDrawQueueStandard2Policy5020DC0D
      - idevelopDrawQueueStandard2368FBC93
      - idevelopDrawQueueStandard3Module5idevelopDrawTopicC62995159D09D12C
      - idevelopDrawQueueStandard3PolicyC274F6D3
      - idevelopDrawQueueStandard3769393EA
    Metadata:
      aws:cdk:path: Module5/sqsPolicy
  ec2InstanceRole947545F4:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action: sts:AssumeRole
            Effect: Allow
            Principal:
              Service:
                Fn::Join:
                  - ""
                  - - ec2.
                    - Ref: AWS::URLSuffix
        Version: "2012-10-17"
      ManagedPolicyArns:
        - Fn::Join:
            - ""
            - - "arn:"
              - Ref: AWS::Partition
              - :iam::aws:policy/AWSElasticBeanstalkMulticontainerDocker
        - Fn::Join:
            - ""
            - - "arn:"
              - Ref: AWS::Partition
              - :iam::aws:policy/AWSElasticBeanstalkWorkerTier
        - Fn::Join:
            - ""
            - - "arn:"
              - Ref: AWS::Partition
              - :iam::aws:policy/AWSElasticBeanstalkWebTier
        - Fn::Join:
            - ""
            - - "arn:"
              - Ref: AWS::Partition
              - :iam::aws:policy/AmazonEC2FullAccess
        - Fn::Join:
            - ""
            - - "arn:"
              - Ref: AWS::Partition
              - :iam::aws:policy/AmazonKinesisFullAccess
        - Fn::Join:
            - ""
            - - "arn:"
              - Ref: AWS::Partition
              - :iam::aws:policy/AmazonDynamoDBFullAccess
        - Fn::Join:
            - ""
            - - "arn:"
              - Ref: AWS::Partition
              - :iam::aws:policy/AWSCodeCommitFullAccess
      Policies:
        - PolicyDocument:
            Statement:
              - Action:
                  - s3:Get*
                  - s3:List*
                Effect: Allow
                Resource: "*"
            Version: "2012-10-17"
          PolicyName: allowS3
      RoleName: EC2InstanceRole
    Metadata:
      aws:cdk:path: Module5/ec2InstanceRole/Resource
  ec2InstanceProfile:
    Type: AWS::IAM::InstanceProfile
    Properties:
      Roles:
        - Ref: ec2InstanceRole947545F4
      InstanceProfileName: ec2InstanceProfile
    Metadata:
      aws:cdk:path: Module5/ec2InstanceProfile
  EC2InstanceSecurityGroup18C4F19E:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Module5/EC2InstanceSecurityGroup
      GroupName: EC2InstanceSecurityGroup
      SecurityGroupEgress:
        - CidrIp: 0.0.0.0/0
          Description: Allow all outbound traffic by default
          IpProtocol: "-1"
      SecurityGroupIngress:
        - CidrIp: 0.0.0.0/0
          Description: from 0.0.0.0/0:22
          FromPort: 22
          IpProtocol: tcp
          ToPort: 22
        - CidrIp: 0.0.0.0/0
          Description: from 0.0.0.0/0:443
          FromPort: 443
          IpProtocol: tcp
          ToPort: 443
      VpcId:
        Ref: DevAxNetworkVPC049CF20B
    Metadata:
      aws:cdk:path: Module5/EC2InstanceSecurityGroup/Resource
  EC2InstanceKPL:
    Type: AWS::EC2::Instance
    Properties:
      IamInstanceProfile:
        Ref: ec2InstanceProfile
      ImageId:
        Fn::FindInMap:
          - AmazonLinuxAMI
          - Ref: AWS::Region
          - AMI
      InstanceType: t2.micro
      KeyName:
        Ref: EEKeyPair
      NetworkInterfaces:
        - AssociatePublicIpAddress: true
          DeviceIndex: "0"
          GroupSet:
            - Fn::GetAtt:
                - EC2InstanceSecurityGroup18C4F19E
                - GroupId
          SubnetId:
            Ref: DevAxNetworkVPCpublicSubnet2Subnet0FE75CE7
      SourceDestCheck: true
      Tags:
        - Key: Name
          Value: KPL_Instance
      UserData:
        Fn::Base64: >
          #!/bin/bash

          yum -y update

          yum -y install git

          mkdir /home/ec2-user/.aws

          echo "[default]" >> /home/ec2-user/.aws/credentials

          echo "region = ap-southeast-2" >> /home/ec2-user/.aws/credentials

          wget http://mirror.olnevhost.net/pub/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz

          tar xzvf apache-maven-3.3.9-bin.tar.gz -C /opt/

          export PATH=/opt/apache-maven-3.3.9/bin:$PATH

          yum -y install java-1.8.0-openjdk-devel

          yum -y remove java-1.7.0-openjdk
    DependsOn:
      - ec2InstanceRole947545F4
    Metadata:
      aws:cdk:path: Module5/EC2InstanceKPL
  EC2InstanceKCL:
    Type: AWS::EC2::Instance
    Properties:
      IamInstanceProfile:
        Ref: ec2InstanceProfile
      ImageId:
        Fn::FindInMap:
          - AmazonLinuxAMI
          - Ref: AWS::Region
          - AMI
      InstanceType: t2.micro
      KeyName:
        Ref: EEKeyPair
      NetworkInterfaces:
        - AssociatePublicIpAddress: true
          DeviceIndex: "0"
          GroupSet:
            - Fn::GetAtt:
                - EC2InstanceSecurityGroup18C4F19E
                - GroupId
          SubnetId:
            Ref: DevAxNetworkVPCpublicSubnet2Subnet0FE75CE7
      SourceDestCheck: true
      Tags:
        - Key: Name
          Value: KCL_Instance
      UserData:
        Fn::Base64:
          Fn::Join:
            - ""
            - - >-
                #!/bin/bash

                yum -y update

                yum -y install git

                mkdir /home/ec2-user/.aws

                echo "[default]" >> /home/ec2-user/.aws/credentials

                echo "region = ap-southeast-2" >> /home/ec2-user/.aws/credentials

                wget http://mirror.olnevhost.net/pub/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz

                tar xzvf apache-maven-3.3.9-bin.tar.gz -C /opt/

                export PATH=/opt/apache-maven-3.3.9/bin:$PATH

                yum -y install java-1.8.0-openjdk-devel

                yum -y remove java-1.7.0-openjdk

                ELASTICSRCH=$(TMP=$(nslookup 
              - Fn::GetAtt:
                  - elasticSearchDomain
                  - DomainEndpoint
              - >
                ) && echo $TMP | awk '{print $10}')

                echo 1 > /proc/sys/net/ipv4/ip_forward

                /sbin/iptables -A FORWARD -p tcp -i eth0 --dport 443 -j ACCEPT

                /sbin/iptables -t nat -A PREROUTING -p tcp -i eth0  --dport 443 -j DNAT --to-destination ${ELASTICSRCH}:443

                /sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

                /sbin/iptables-save > /etc/sysconfig/iptables

                sysctl -w net.ipv4.ip_forward=1
    DependsOn:
      - ec2InstanceRole947545F4
    Metadata:
      aws:cdk:path: Module5/EC2InstanceKCL
  EC2InstanceKCLIPAssociation:
    Type: AWS::EC2::EIPAssociation
    Properties:
      AllocationId:
        Fn::GetAtt:
          - EC2InstanceKCLEIP
          - AllocationId
      InstanceId:
        Ref: EC2InstanceKCL
    Metadata:
      aws:cdk:path: Module5/EC2InstanceKCLIPAssociation
  CreateGitCredsFunction9D6697C5:
    Type: AWS::Lambda::Function
    Properties:
      Code:
        ZipFile: >
          import boto3

          import cfnresponse


          def lambda_handler(event,context):
              print(event)
              response = {}
              try:
                  if event['RequestType'] == 'Delete':
                      iam = boto3.client('iam')
                      credentials = iam.list_service_specific_credentials(UserName='awsstudent',ServiceName='codecommit.amazonaws.com')
                      serviceSpecificCredentialId = credentials['ServiceSpecificCredentials'][0]['ServiceSpecificCredentialId']
                      delete = iam.delete_service_specific_credential(UserName='awsstudent', ServiceSpecificCredentialId=serviceSpecificCredentialId)
                      cfnresponse.send(event, context, cfnresponse.SUCCESS,response)
                  else:
                      iam = boto3.client('iam')
                      gitcreds = iam.create_service_specific_credential(UserName='awsstudent',ServiceName='codecommit.amazonaws.com')
                      response['GitUserName'] = gitcreds['ServiceSpecificCredential']['ServiceUserName']
                      response['GitPassword'] = gitcreds['ServiceSpecificCredential']['ServicePassword']
                      cfnresponse.send(event, context, cfnresponse.SUCCESS,response)
              except Exception as e:
                  print(e)
                  response['Status'] = 'FAILED'
                  response['Reason'] = 'Git failed, see log for details'
                  cfnresponse.send(event, context, cfnresponse.FAILED,response)
      Handler: index.lambda_handler
      Role:
        Fn::GetAtt:
          - CreateGitCredsRole385E94AC
          - Arn
      Runtime: python3.7
      FunctionName: CreateGitCredsFunction
      MemorySize: 128
      Timeout: 90
    DependsOn:
      - CreateGitCredsRole385E94AC
    Metadata:
      aws:cdk:path: Module5/CreateGitCredsFunction/Resource
  GitCredsCR:
    Type: AWS::CloudFormation::CustomResource
    Properties:
      ServiceToken:
        Fn::GetAtt:
          - CreateGitCredsFunction9D6697C5
          - Arn
    UpdateReplacePolicy: Delete
    DeletionPolicy: Delete
    Metadata:
      aws:cdk:path: Module5/GitCredsCR/Default
  CDKMetadata:
    Type: AWS::CDK::Metadata
    Properties:
      Modules: aws-cdk=1.73.0,@aws-cdk/assets=1.73.0,@aws-cdk/aws-applicationautoscaling=1.73.0,@aws-cdk/aws-autoscaling-common=1.73.0,@aws-cdk/aws-cloudwatch=1.73.0,@aws-cdk/aws-codeguruprofiler=1.73.0,@aws-cdk/aws-cognito=1.73.0,@aws-cdk/aws-ec2=1.73.0,@aws-cdk/aws-elasticsearch=1.73.0,@aws-cdk/aws-events=1.73.0,@aws-cdk/aws-iam=1.73.0,@aws-cdk/aws-kinesis=1.73.0,@aws-cdk/aws-kms=1.73.0,@aws-cdk/aws-lambda=1.73.0,@aws-cdk/aws-logs=1.73.0,@aws-cdk/aws-rds=1.73.0,@aws-cdk/aws-s3=1.73.0,@aws-cdk/aws-s3-assets=1.73.0,@aws-cdk/aws-sam=1.73.0,@aws-cdk/aws-secretsmanager=1.73.0,@aws-cdk/aws-sns=1.73.0,@aws-cdk/aws-sns-subscriptions=1.73.0,@aws-cdk/aws-sqs=1.73.0,@aws-cdk/aws-ssm=1.73.0,@aws-cdk/cloud-assembly-schema=1.73.0,@aws-cdk/core=1.73.0,@aws-cdk/custom-resources=1.73.0,@aws-cdk/cx-api=1.73.0,@aws-cdk/region-info=1.73.0,jsii-runtime=node.js/v12.18.3
    Metadata:
      aws:cdk:path: Module5/CDKMetadata/Default
    Condition: CDKMetadataAvailable
Conditions:
  AwsCdkKinesisEncryptedStreamsUnsupportedRegions:
    Fn::Or:
      - Fn::Equals:
          - Ref: AWS::Region
          - cn-north-1
      - Fn::Equals:
          - Ref: AWS::Region
          - cn-northwest-1
  CDKMetadataAvailable:
    Fn::Or:
      - Fn::Or:
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-east-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-northeast-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-northeast-2
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-south-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-southeast-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-southeast-2
          - Fn::Equals:
              - Ref: AWS::Region
              - ca-central-1
          - Fn::Equals:
              - Ref: AWS::Region
              - cn-north-1
          - Fn::Equals:
              - Ref: AWS::Region
              - cn-northwest-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-central-1
      - Fn::Or:
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-north-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-west-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-west-2
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-west-3
          - Fn::Equals:
              - Ref: AWS::Region
              - me-south-1
          - Fn::Equals:
              - Ref: AWS::Region
              - sa-east-1
          - Fn::Equals:
              - Ref: AWS::Region
              - us-east-1
          - Fn::Equals:
              - Ref: AWS::Region
              - us-east-2
          - Fn::Equals:
              - Ref: AWS::Region
              - us-west-1
          - Fn::Equals:
              - Ref: AWS::Region
              - us-west-2
Mappings:
  AmazonLinuxAMI:
    us-east-1:
      AMI: ami-1ecae776
    us-west-1:
      AMI: ami-d114f295
    us-west-2:
      AMI: ami-e7527ed7
    eu-west-1:
      AMI: ami-a10897d6
    eu-central-1:
      AMI: ami-a8221fb5
    sa-east-1:
      AMI: ami-b52890a8
    ap-southeast-1:
      AMI: ami-68d8e93a
    ap-southeast-2:
      AMI: ami-fd9cecc7
    ap-northeast-1:
      AMI: ami-cbf90ecb
Outputs:
  GitUserName:
    Description: Git Username
    Value:
      Fn::GetAtt:
        - GitCredsCR
        - GitUserName
  GitPassword:
    Description: Git Password
    Value:
      Fn::GetAtt:
        - GitCredsCR
        - GitPassword
  RDSEndpoint:
    Description: RDS database endpoint
    Value:
      Fn::GetAtt:
        - DBinstanceA5CF359B
        - Endpoint.Address
  ElasticsearchEndpoint:
    Description: The endpoint for ElasticSearch
    Value:
      Fn::GetAtt:
        - elasticSearchDomain
        - DomainEndpoint
  EC2InstanceKinesisProducer:
    Description: Public IP address for Kinesis Producer EC2 instance
    Value:
      Fn::GetAtt:
        - EC2InstanceKPL
        - PublicIp
  EC2InstanceKinesisConsumer:
    Description: Public IP address for Kinesis Consumer EC2 instance
    Value:
      Fn::GetAtt:
        - EC2InstanceKCL
        - PublicIp
  QueueUrl1:
    Description: SQS.Standard.QueueUrl
    Value:
      Ref: idevelopDrawQueueStandard12D32FE88
  QueueUrl2:
    Description: SQS.Secondary.QueueUrl
    Value:
      Ref: idevelopDrawQueueStandard2368FBC93
  QueueUrl3:
    Description: SQS.Tertiary.QueueUrl
    Value:
      Ref: idevelopDrawQueueStandard3769393EA
  FIFOQueueUrl:
    Description: SQS.FIFO.QueueUrl
    Value:
      Ref: idevelopDrawQueueFIFOB708BF02
  TopicARN:
    Description: SNS.TopicARN
    Value:
      Ref: idevelopDrawTopicF93DE7CF
  CognitoIdentityPoolId:
    Description: Cognito.IdentityPoolId
    Value:
      Ref: CIPMessageDraw

