templates/lab_template-old.yml [811:934]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            - "curl -O https://[[website]]/support/sagemaker_policy.json"
            - "curl -O https://[[website]]/support/peer_vpcs.py"
            - "echo \"$(date \"+%F %T\") * downloaded lab assets\" >> /bootstrap.log"
            - "mkdir -p /home/ec2-user/.aws"
            - "touch /home/ec2-user/.aws/config"
            - "echo \"[default]\" >> /home/ec2-user/.aws/config"
            - !Sub "echo \"region = ${AWS::Region}\" >> /home/ec2-user/.aws/config"
            - "chown -R ec2-user:ec2-user /home/ec2-user/.aws"
            - "aws --version >> /bootstrap.log"
            - "echo \"$(date \"+%F %T\") * configured aws cli\" >> /bootstrap.log"
            - 'export ANALYTICSURI="https://[[apigw]]/v1/track" && echo "export ANALYTICSURI=\"$ANALYTICSURI\"" >> /home/ec2-user/.bashrc'
            - !Sub 'export AGREETRACKING="${agreeTracking}" && echo "export AGREETRACKING=\"$AGREETRACKING\"" >> /home/ec2-user/.bashrc'
            - !Sub 'export STACKREGION="${AWS::Region}" && echo "export STACKREGION=\"$STACKREGION\"" >> /home/ec2-user/.bashrc'
            - !Sub 'export STACKNAME="${AWS::StackName}" && echo "export STACKNAME=\"$STACKNAME\"" >> /home/ec2-user/.bashrc'
            - Fn::Join:
              - ""
              - - 'export STACKUUID="'
                - !Select
                  - 2
                  - !Split
                    - "/"
                    - !Ref 'AWS::StackId'
                - '" && echo "export STACKUUID=\"$STACKUUID\"" >> /home/ec2-user/.bashrc'
            - !Sub 'export DATABUCKET="${bucketLabData}" && echo "export DATABUCKET=\"$DATABUCKET\"" >> /home/ec2-user/.bashrc'
            - !Sub 'export DBCLUSTERPG="${cpgClusterParams}" && echo "export DBCLUSTERPG=\"$DBCLUSTERPG\"" >> /home/ec2-user/.bashrc'
            - "echo \"$(date \"+%F %T\") * environment vars initialized\" >> /bootstrap.log"
            - Fn::If:
              - condDeployDBCluster
              - !Sub "export SECRETSTRING=`aws secretsmanager get-secret-value --secret-id \"${secretClusterAdminUser}\" --region ${AWS::Region} | jq -r '.SecretString'` && export DBPASS=`echo $SECRETSTRING | jq -r '.password'` && export DBUSER=`echo $SECRETSTRING | jq -r '.username'`"
              - ""
            - Fn::If:
              - condDeployDBCluster
              - 'echo "export DBPASS=\"$DBPASS\"" >> /home/ec2-user/.bashrc && echo "export DBUSER=$DBUSER" >> /home/ec2-user/.bashrc'
              - ""
            - Fn::If:
              - condDeployDBCluster
              - "echo \"$(date \"+%F %T\") * db credentials initialized\" >> /bootstrap.log"
              - "echo \"$(date \"+%F %T\") * skipped db credentials, no cluster\" >> /bootstrap.log"
            - "chown -R ec2-user:ec2-user /home/ec2-user/environment/*"
            - "echo \"$(date \"+%F %T\") * updated file ownership\" >> /bootstrap.log"
            - !Sub "curl -X PUT -H 'Content-Type:' --data-binary '{\"Status\": \"SUCCESS\", \"Reason\": \"Bootstrap complete\", \"UniqueId\": \"${AWS::StackId}\", \"Data\": \"Bootstrap complete\"}' \"${bootstrapWaitHandle}\""
            - "echo \"$(date \"+%F %T\") * signal bootstrap complete\" >> /bootstrap.log"
            - "shutdown -r now"

## Create the Apache Superset host
  supersetHost:
    Type: "AWS::EC2::Instance"
    Condition: condDeployGDBResources
    Properties:
      SubnetId: !Ref sub2Public
      InstanceType: !FindInMap [ RegionalSettings, !Ref "AWS::Region", supersetType ]
      SecurityGroupIds: [ !Ref supersetSecGroup ]
      Tags:
        - Key: Name
          Value: !If [ condEventEngine, "auroralab-superset-host", !Sub "${AWS::StackName}-superset-host" ]
      BlockDeviceMappings:
        - DeviceName: /dev/sda1
          Ebs:
            DeleteOnTermination: true
            VolumeSize: 80
            VolumeType: gp2
      ImageId: !Ref LatestAmiId
      IamInstanceProfile: !Ref profileClientIDE
      UserData:
        Fn::Base64:
          Fn::Join:
            - "\n"
            - - !Sub |
                #!/bin/bash
                cd /tmp

                # start bootstrap
                echo "$(date "+%F %T") * running as $(whoami)" >> /debug.log

                # install Docker and necessary packages
                echo "$(date "+%F %T") Updating packages and install Docker" >> /debug.log           
                yum update -y
                amazon-linux-extras install docker
                service docker start >> /debug.log
                usermod -a -G docker ec2-user
                usermod -a -G docker ssm-user
                echo "$(date "+%F %T") * installed docker" >> /debug.log

                # export credentials
              - Fn::Join:
                  - ""
                  - - 'export ADMINUSER="'
                    - !FindInMap [ GDBSettings, superset, username ]
                    - '"'
              - Fn::Join:
                  - ""
                  - - 'export ADMINPASS="'
                    - !FindInMap [ GDBSettings, superset, password ]
                    - '"'
              - !Sub |
                # use docker to handle Apache Superset
                docker run -d -p 80:8088 --name superset apache/superset >> /debug.log
                docker exec -i superset superset fab create-admin \
                  --username "$ADMINUSER" \
                  --firstname Superset \
                  --lastname Admin \
                  --email admin@superset.com \
                  --password "$ADMINPASS" >> /debug.log
                docker exec -i superset superset db upgrade >> /debug.log
                docker exec -i superset superset load_examples >> /debug.log
                docker exec -i superset superset init >> /debug.log
                echo "$(date "+%F %T") superset deployed" >> /debug.log


## Create cluster parameter group
  cpgClusterParams:
    Type: "AWS::RDS::DBClusterParameterGroup"
    Properties:
      Description: !If [ condEventEngine, "auroralab-mysql-cluster-params", !Sub "${AWS::StackName}-mysql-cluster-params" ]
      Family: !FindInMap [ ClusterSettings, global, dbFamily ]
      Parameters:
        aws_default_s3_role: !GetAtt roleServiceIntegration.Arn
        innodb_stats_persistent_sample_pages: "256"
        slow_query_log: "1"
        long_query_time: "1"
        log_output: FILE
      Tags:
        - Key: Name
          Value: !If [ condEventEngine, "auroralab-mysql-cluster-params", !Sub "${AWS::StackName}-mysql-cluster-params" ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



templates/lab_template.yml [824:947]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            - "curl -O https://[[website]]/support/sagemaker_policy.json"
            - "curl -O https://[[website]]/support/peer_vpcs.py"
            - "echo \"$(date \"+%F %T\") * downloaded lab assets\" >> /bootstrap.log"
            - "mkdir -p /home/ec2-user/.aws"
            - "touch /home/ec2-user/.aws/config"
            - "echo \"[default]\" >> /home/ec2-user/.aws/config"
            - !Sub "echo \"region = ${AWS::Region}\" >> /home/ec2-user/.aws/config"
            - "chown -R ec2-user:ec2-user /home/ec2-user/.aws"
            - "aws --version >> /bootstrap.log"
            - "echo \"$(date \"+%F %T\") * configured aws cli\" >> /bootstrap.log"
            - 'export ANALYTICSURI="https://[[apigw]]/v1/track" && echo "export ANALYTICSURI=\"$ANALYTICSURI\"" >> /home/ec2-user/.bashrc'
            - !Sub 'export AGREETRACKING="${agreeTracking}" && echo "export AGREETRACKING=\"$AGREETRACKING\"" >> /home/ec2-user/.bashrc'
            - !Sub 'export STACKREGION="${AWS::Region}" && echo "export STACKREGION=\"$STACKREGION\"" >> /home/ec2-user/.bashrc'
            - !Sub 'export STACKNAME="${AWS::StackName}" && echo "export STACKNAME=\"$STACKNAME\"" >> /home/ec2-user/.bashrc'
            - Fn::Join:
              - ""
              - - 'export STACKUUID="'
                - !Select
                  - 2
                  - !Split
                    - "/"
                    - !Ref 'AWS::StackId'
                - '" && echo "export STACKUUID=\"$STACKUUID\"" >> /home/ec2-user/.bashrc'
            - !Sub 'export DATABUCKET="${bucketLabData}" && echo "export DATABUCKET=\"$DATABUCKET\"" >> /home/ec2-user/.bashrc'
            - !Sub 'export DBCLUSTERPG="${cpgClusterParams}" && echo "export DBCLUSTERPG=\"$DBCLUSTERPG\"" >> /home/ec2-user/.bashrc'
            - "echo \"$(date \"+%F %T\") * environment vars initialized\" >> /bootstrap.log"
            - Fn::If:
              - condDeployDBCluster
              - !Sub "export SECRETSTRING=`aws secretsmanager get-secret-value --secret-id \"${secretClusterAdminUser}\" --region ${AWS::Region} | jq -r '.SecretString'` && export DBPASS=`echo $SECRETSTRING | jq -r '.password'` && export DBUSER=`echo $SECRETSTRING | jq -r '.username'`"
              - ""
            - Fn::If:
              - condDeployDBCluster
              - 'echo "export DBPASS=\"$DBPASS\"" >> /home/ec2-user/.bashrc && echo "export DBUSER=$DBUSER" >> /home/ec2-user/.bashrc'
              - ""
            - Fn::If:
              - condDeployDBCluster
              - "echo \"$(date \"+%F %T\") * db credentials initialized\" >> /bootstrap.log"
              - "echo \"$(date \"+%F %T\") * skipped db credentials, no cluster\" >> /bootstrap.log"
            - "chown -R ec2-user:ec2-user /home/ec2-user/environment/*"
            - "echo \"$(date \"+%F %T\") * updated file ownership\" >> /bootstrap.log"
            - !Sub "curl -X PUT -H 'Content-Type:' --data-binary '{\"Status\": \"SUCCESS\", \"Reason\": \"Bootstrap complete\", \"UniqueId\": \"${AWS::StackId}\", \"Data\": \"Bootstrap complete\"}' \"${bootstrapWaitHandle}\""
            - "echo \"$(date \"+%F %T\") * signal bootstrap complete\" >> /bootstrap.log"
            - "shutdown -r now"

## Create the Apache Superset host
  supersetHost:
    Type: "AWS::EC2::Instance"
    Condition: condDeployGDBResources
    Properties:
      SubnetId: !Ref sub2Public
      InstanceType: !FindInMap [ RegionalSettings, !Ref "AWS::Region", supersetType ]
      SecurityGroupIds: [ !Ref supersetSecGroup ]
      Tags:
        - Key: Name
          Value: !If [ condEventEngine, "auroralab-superset-host", !Sub "${AWS::StackName}-superset-host" ]
      BlockDeviceMappings:
        - DeviceName: /dev/sda1
          Ebs:
            DeleteOnTermination: true
            VolumeSize: 80
            VolumeType: gp2
      ImageId: !Ref LatestAmiId
      IamInstanceProfile: !Ref profileClientIDE
      UserData:
        Fn::Base64:
          Fn::Join:
            - "\n"
            - - !Sub |
                #!/bin/bash
                cd /tmp

                # start bootstrap
                echo "$(date "+%F %T") * running as $(whoami)" >> /debug.log

                # install Docker and necessary packages
                echo "$(date "+%F %T") Updating packages and install Docker" >> /debug.log           
                yum update -y
                amazon-linux-extras install docker
                service docker start >> /debug.log
                usermod -a -G docker ec2-user
                usermod -a -G docker ssm-user
                echo "$(date "+%F %T") * installed docker" >> /debug.log

                # export credentials
              - Fn::Join:
                  - ""
                  - - 'export ADMINUSER="'
                    - !FindInMap [ GDBSettings, superset, username ]
                    - '"'
              - Fn::Join:
                  - ""
                  - - 'export ADMINPASS="'
                    - !FindInMap [ GDBSettings, superset, password ]
                    - '"'
              - !Sub |
                # use docker to handle Apache Superset
                docker run -d -p 80:8088 --name superset apache/superset >> /debug.log
                docker exec -i superset superset fab create-admin \
                  --username "$ADMINUSER" \
                  --firstname Superset \
                  --lastname Admin \
                  --email admin@superset.com \
                  --password "$ADMINPASS" >> /debug.log
                docker exec -i superset superset db upgrade >> /debug.log
                docker exec -i superset superset load_examples >> /debug.log
                docker exec -i superset superset init >> /debug.log
                echo "$(date "+%F %T") superset deployed" >> /debug.log


## Create cluster parameter group
  cpgClusterParams:
    Type: "AWS::RDS::DBClusterParameterGroup"
    Properties:
      Description: !If [ condEventEngine, "auroralab-mysql-cluster-params", !Sub "${AWS::StackName}-mysql-cluster-params" ]
      Family: !FindInMap [ ClusterSettings, global, dbFamily ]
      Parameters:
        aws_default_s3_role: !GetAtt roleServiceIntegration.Arn
        innodb_stats_persistent_sample_pages: "256"
        slow_query_log: "1"
        long_query_time: "1"
        log_output: FILE
      Tags:
        - Key: Name
          Value: !If [ condEventEngine, "auroralab-mysql-cluster-params", !Sub "${AWS::StackName}-mysql-cluster-params" ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



