cloudformation/FIXEngineApplication.yml [3107:3387]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Properties:
      DBSubnetGroupDescription: !Join
        - ''
        - - 'Private subnets defined in '
          - !Ref 'AWS::StackName'
          - ' stack'
      SubnetIds:
        - !Ref 'PrimaryPrivateSubnet'
        - !Ref 'FailoverPrivateSubnet'
    Type: AWS::RDS::DBSubnetGroup
  RDSInitializationDocument:
    DependsOn:
      - RDSCluster
      - PrimaryRDSInstance
      - FailoverRDSInstance
      - FargateSecurityGroup
      - RDSClusterPrepLogGroup
      - RDSClusterAdminSecret
      - RDSClusterNonAdminSecret
      - RDSClusterPrepExecutionRole
      - RDSClusterPrepInstanceRoleProfile
      - RDSClusterPrepSecurityGroupEgressToRDS
    Properties:
      Content:
        assumeRole: '{{ExecutionRoleArn}}'
        description: !Join
          - ''
          - - 'Configure a FIX Engine DB cluster created by CloudFormation stack '
            - !Ref 'AWS::StackName'
        mainSteps:
          - action: aws:runInstances
            inputs:
              IamInstanceProfileName: !Ref 'RDSClusterPrepInstanceRoleProfile'
              ImageId: '{{LatestUbuntu2004AMIId}}'
              InstanceType: t3a.small
              MaxInstanceCount: 1
              MinInstanceCount: 1
              SecurityGroupIds:
                - !Ref 'RDSClusterPrepSecurityGroup'
              SubnetId: !Ref 'PrimaryPrivateSubnet'
              TagSpecifications:
                - ResourceType: instance
                  Tags:
                    - Key: Name
                      Value: !Join
                        - '-'
                        - - !Ref 'AWS::StackName'
                          - RDSInitializer
                    - Key: LaunchedBy
                      Value: SSMAutomation
                    - Key: StackName
                      Value: !Ref 'AWS::StackName'
            maxAttempts: 3
            name: LaunchInstance
            onFailure: step:SignalFailure
            timeoutSeconds: 300
          - action: aws:runCommand
            inputs:
              CloudWatchOutputConfig:
                CloudWatchLogGroupName: !Ref 'RDSClusterPrepLogGroup'
                CloudWatchOutputEnabled: true
              DocumentName: AWS-RunShellScript
              InstanceIds:
                - '{{LaunchInstance.InstanceIds}}'
              Parameters:
                commands:
                  - sudo apt-get update 2>/dev/null
                  - sudo apt-get install awscli mysql-client jq -y 2>/dev/null
                  - '#sudo yum install jq mysql -y'
                  - !Join
                    - ''
                    - - DB_HOST=
                      - !GetAtt 'RDSCluster.Endpoint.Address'
                  - '# Retrieves & Assigns to Variables Admin DB Credentials'
                  - !Join
                    - ''
                    - - 'ADMIN_DB_SECRET=$(aws secretsmanager get-secret-value --secret-id '
                      - !Join
                        - '-'
                        - - !Select
                            - 0
                            - !Split
                              - '-'
                              - !Select
                                - 6
                                - !Split
                                  - ':'
                                  - !Ref 'RDSClusterAdminSecret'
                          - !Select
                            - 1
                            - !Split
                              - '-'
                              - !Select
                                - 6
                                - !Split
                                  - ':'
                                  - !Ref 'RDSClusterAdminSecret'
                      - ' --region '
                      - !Ref 'AWS::Region'
                      - ' | jq --raw-output .SecretString)'
                  - ADMIN_DB_USERNAME=$(jq -n -r --argjson data "$ADMIN_DB_SECRET"
                    '$data.username')
                  - export MYSQL_PWD=$(jq -n -r --argjson data "$ADMIN_DB_SECRET"
                    '$data.password')
                  - '# Retrieves & Assigns to Variables Non-Admin DB Credentials'
                  - !Join
                    - ''
                    - - 'NON_ADMIN_DB_SECRET=$(aws secretsmanager get-secret-value
                        --secret-id '
                      - !Join
                        - '-'
                        - - !Select
                            - 0
                            - !Split
                              - '-'
                              - !Select
                                - 6
                                - !Split
                                  - ':'
                                  - !Ref 'RDSClusterNonAdminSecret'
                          - !Select
                            - 1
                            - !Split
                              - '-'
                              - !Select
                                - 6
                                - !Split
                                  - ':'
                                  - !Ref 'RDSClusterNonAdminSecret'
                      - ' --region '
                      - !Ref 'AWS::Region'
                      - ' | jq --raw-output .SecretString)'
                  - NON_ADMIN_DB_USERNAME=$(jq -n -r --argjson data "$NON_ADMIN_DB_SECRET"
                    '$data.username')
                  - NON_ADMIN_DB_PASSWORD=$(jq -n -r --argjson data "$NON_ADMIN_DB_SECRET"
                    '$data.password')
                  - "echo \"\nDROP DATABASE IF EXISTS <database-name>;\n\nCREATE DATABASE\
                    \ <database-name>;\n\nUSE <database-name>;\n\n/* Deletes (if necessary)\
                    \ and Creates Non-Admin User */\nCREATE USER '$NON_ADMIN_DB_USERNAME'\
                    \ IDENTIFIED BY '$NON_ADMIN_DB_PASSWORD';\n\nCREATE TABLE sessions\
                    \ (\n  beginstring CHAR(8) NOT NULL,\n  sendercompid VARCHAR(64)\
                    \ NOT NULL,\n  targetcompid VARCHAR(64) NOT NULL,\n  session_qualifier\
                    \ VARCHAR(64) NOT NULL,\n  creation_time DATETIME NOT NULL,\n\
                    \  incoming_seqnum INT NOT NULL, \n  outgoing_seqnum INT NOT NULL,\n\
                    \  PRIMARY KEY (beginstring, sendercompid, targetcompid, session_qualifier)\n\
                    );\nGRANT SELECT, INSERT, UPDATE, DELETE ON <database-name>.sessions\
                    \ TO '$NON_ADMIN_DB_USERNAME';\n\nCREATE TABLE messages (\n  beginstring\
                    \ CHAR(8) NOT NULL,\n  sendercompid VARCHAR(64) NOT NULL,\n  targetcompid\
                    \ VARCHAR(64) NOT NULL,\n  session_qualifier VARCHAR(64) NOT NULL,\n\
                    \  msgseqnum INT NOT NULL, \n  message BLOB NOT NULL,\n  PRIMARY\
                    \ KEY (beginstring, sendercompid, targetcompid, session_qualifier,\
                    \ msgseqnum)\n);\nGRANT SELECT, INSERT, UPDATE, DELETE ON <database-name>.messages\
                    \ TO '$NON_ADMIN_DB_USERNAME';\n\nCREATE TABLE messages_log (\n\
                    \  id INT UNSIGNED NOT NULL AUTO_INCREMENT,\n  time DATETIME NOT\
                    \ NULL,\n  time_milliseconds INT NOT NULL,\n  beginstring CHAR(8),\n\
                    \  sendercompid VARCHAR(64),\n  targetcompid VARCHAR(64),\n  session_qualifier\
                    \ VARCHAR(64),\n  text BLOB NOT NULL,\n  PRIMARY KEY (id)\n);\n\
                    GRANT SELECT, INSERT, UPDATE, DELETE ON <database-name>.messages_log\
                    \ TO '$NON_ADMIN_DB_USERNAME';\n\nCREATE TABLE messages_backup_log\
                    \ (\n  id INT UNSIGNED NOT NULL AUTO_INCREMENT,\n  time DATETIME\
                    \ NOT NULL,\n  time_milliseconds INT NOT NULL,\n  beginstring\
                    \ CHAR(8),\n  sendercompid VARCHAR(64),\n  targetcompid VARCHAR(64),\n\
                    \  session_qualifier VARCHAR(64),\n  text BLOB NOT NULL,\n  PRIMARY\
                    \ KEY (id)\n);\nGRANT SELECT, INSERT, UPDATE, DELETE ON <database-name>.messages_backup_log\
                    \ TO '$NON_ADMIN_DB_USERNAME';\n\nCREATE TABLE event_log (\n \
                    \ id INT UNSIGNED NOT NULL AUTO_INCREMENT,\n  time DATETIME NOT\
                    \ NULL,\n  time_milliseconds INT NOT NULL,\n  beginstring CHAR(8),\n\
                    \  sendercompid VARCHAR(64),\n  targetcompid VARCHAR(64),\n  session_qualifier\
                    \ VARCHAR(64),\n  text BLOB NOT NULL,\n  PRIMARY KEY (id)\n);\n\
                    GRANT SELECT, INSERT, UPDATE, DELETE ON <database-name>.event_log\
                    \ TO '$NON_ADMIN_DB_USERNAME';\n\nCREATE TABLE event_backup_log\
                    \ (\n  id INT UNSIGNED NOT NULL AUTO_INCREMENT,\n  time DATETIME\
                    \ NOT NULL,\n  time_milliseconds INT NOT NULL,\n  beginstring\
                    \ CHAR(8),\n  sendercompid VARCHAR(64),\n  targetcompid VARCHAR(64),\n\
                    \  session_qualifier VARCHAR(64),\n  text BLOB NOT NULL,\n  PRIMARY\
                    \ KEY (id)\n);\nGRANT SELECT, INSERT, UPDATE, DELETE ON <database-name>.event_backup_log\
                    \ TO '$NON_ADMIN_DB_USERNAME';\n\nCREATE TABLE ActiveEngine  (\n\
                    \  TS TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n  ipAddress VARCHAR(16)\
                    \ NOT NULL,\n  PRIMARY KEY (TS, ipAddress)\n);\nGRANT SELECT,\
                    \ UPDATE ON <database-name>.ActiveEngine TO '$NON_ADMIN_DB_USERNAME';\n\
                    \nINSERT INTO ActiveEngine VALUES (NOW(), 'none');\n\nDELIMITER\
                    \ //\n\ncreate procedure EngineStatus(IN ipAdd varchar(16), OUT\
                    \ value int, OUT lastIpAdd varchar(16), OUT lastTimestamp DATETIME,\
                    \ OUT timeNow DATETIME, OUT timeDiffSec int)\nBEGIN\n\tSTART TRANSACTION;\n\
                    \    SET timeNow = NOW();\n    SELECT TS, timestampdiff (second,\
                    \ TS, timeNow), ipAddress INTO lastTimestamp, timeDiffSec, lastIpAdd\
                    \ FROM ActiveEngine;\n    IF timeDiffSec <= 3 AND ipAdd != lastIpAdd\
                    \ THEN            # If another IP is the leader and not stale\
                    \ \n      SET value = 0;                                     \
                    \      # Then I do nothing and keep waiting\n    ELSE \n     \
                    \ UPDATE ActiveEngine SET TS = timeNow, ipAddress = ipAdd; # Else\
                    \ I am going to be the leader (update DB to say this) \n     \
                    \ IF (timeDiffSec > 3) THEN                                # \
                    \  If the last leader is stale (no matter if it was me or another\
                    \ IP)\n        SET value = -1;                               \
                    \         #   Then I need to become the new leader\n      ELSE\n\
                    \        SET value = 1;                                      \
                    \   #   Else I am still the active leader\n      END IF;\n   \
                    \ END IF;\n    COMMIT;\nEND //\n\nDELIMITER ;\n\nGRANT SELECT\
                    \ ON mysql.proc TO '$NON_ADMIN_DB_USERNAME';\nGRANT EXECUTE ON\
                    \ PROCEDURE <database-name>.EngineStatus TO '$NON_ADMIN_DB_USERNAME';\n\
                    \n\" >> /tmp/rds-cluster-prep.sql"
                  - !Join
                    - ''
                    - - '#sudo sed -i ''s/<database-name>/`quickfix-'
                      - !Select
                        - 2
                        - !Split
                          - /
                          - !Ref 'AWS::StackId'
                      - '`/g'' /tmp/rds-cluster-prep.sql'
                  - !Join
                    - ''
                    - - sudo sed -i 's/<database-name>/`quickfix`/g' /tmp/rds-cluster-prep.sql
                  - !Join
                    - ''
                    - - mysql --user $ADMIN_DB_USERNAME --host $DB_HOST --ssl-mode
                        disabled --execute 'source /tmp/rds-cluster-prep.sql'
            name: CreateDBObjects
            onFailure: step:TerminateInstanceOnFailure
          - action: aws:executeAwsApi
            inputs:
              Api: TerminateInstances
              InstanceIds:
                - '{{LaunchInstance.InstanceIds}}'
              Service: ec2
            name: TerminateInstanceOnSuccess
            onFailure: step:SignalFailure
          - action: aws:executeAwsApi
            inputs:
              Api: SignalResource
              LogicalResourceId: RDSClusterInitializationWaiter
              Service: cloudformation
              StackName: !Ref 'AWS::StackName'
              Status: SUCCESS
              UniqueId: !Ref 'RDSCluster'
            isEnd: true
            name: SignalSuccess
            onFailure: step:SignalFailure
          - action: aws:executeAwsApi
            inputs:
              Api: TerminateInstances
              InstanceIds:
                - '{{LaunchInstance.InstanceIds}}'
              Service: ec2
            name: TerminateInstanceOnFailure
            onFailure: step:SignalFailure
          - action: aws:executeAwsApi
            inputs:
              Api: SignalResource
              LogicalResourceId: RDSClusterInitializationWaiter
              Service: cloudformation
              StackName: !Ref 'AWS::StackName'
              Status: FAILURE
              UniqueId: !Ref 'RDSCluster'
            isEnd: true
            name: SignalFailure
        parameters:
          ExecutionRoleArn:
            default: !GetAtt 'RDSClusterPrepExecutionRole.Arn'
            description: The service role to use for this automation.
            type: String
          LatestUbuntu2004AMIId:
            default: '{{ssm:/aws/service/canonical/ubuntu/server/20.04/stable/current/amd64/hvm/ebs-gp2/ami-id}}'
            description: The latest Ubuntu 20.04 LTS AMI queried from the public parameter.
            type: String
        schemaVersion: '0.3'
      DocumentType: Automation
    Type: AWS::SSM::Document
  RDSParameterGroup:
    Properties:
      Description: !Join
        - ''
        - - 'Parameter group for '
          - !Ref 'AWS::StackName'
          - ' stack'
      Family: aurora5.6
      Parameters:
        long_query_time: 5
        slow_query_log: 1
    Type: AWS::RDS::DBParameterGroup
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



cloudformation/FIXEngineVPCApplication.yml [3424:3704]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Properties:
      DBSubnetGroupDescription: !Join
        - ''
        - - 'Private subnets defined in '
          - !Ref 'AWS::StackName'
          - ' stack'
      SubnetIds:
        - !Ref 'PrimaryPrivateSubnet'
        - !Ref 'FailoverPrivateSubnet'
    Type: AWS::RDS::DBSubnetGroup
  RDSInitializationDocument:
    DependsOn:
      - RDSCluster
      - PrimaryRDSInstance
      - FailoverRDSInstance
      - FargateSecurityGroup
      - RDSClusterPrepLogGroup
      - RDSClusterAdminSecret
      - RDSClusterNonAdminSecret
      - RDSClusterPrepExecutionRole
      - RDSClusterPrepInstanceRoleProfile
      - RDSClusterPrepSecurityGroupEgressToRDS
    Properties:
      Content:
        assumeRole: '{{ExecutionRoleArn}}'
        description: !Join
          - ''
          - - 'Configure a FIX Engine DB cluster created by CloudFormation stack '
            - !Ref 'AWS::StackName'
        mainSteps:
          - action: aws:runInstances
            inputs:
              IamInstanceProfileName: !Ref 'RDSClusterPrepInstanceRoleProfile'
              ImageId: '{{LatestUbuntu2004AMIId}}'
              InstanceType: t3a.small
              MaxInstanceCount: 1
              MinInstanceCount: 1
              SecurityGroupIds:
                - !Ref 'RDSClusterPrepSecurityGroup'
              SubnetId: !Ref 'PrimaryPrivateSubnet'
              TagSpecifications:
                - ResourceType: instance
                  Tags:
                    - Key: Name
                      Value: !Join
                        - '-'
                        - - !Ref 'AWS::StackName'
                          - RDSInitializer
                    - Key: LaunchedBy
                      Value: SSMAutomation
                    - Key: StackName
                      Value: !Ref 'AWS::StackName'
            maxAttempts: 3
            name: LaunchInstance
            onFailure: step:SignalFailure
            timeoutSeconds: 300
          - action: aws:runCommand
            inputs:
              CloudWatchOutputConfig:
                CloudWatchLogGroupName: !Ref 'RDSClusterPrepLogGroup'
                CloudWatchOutputEnabled: true
              DocumentName: AWS-RunShellScript
              InstanceIds:
                - '{{LaunchInstance.InstanceIds}}'
              Parameters:
                commands:
                  - sudo apt-get update 2>/dev/null
                  - sudo apt-get install awscli mysql-client jq -y 2>/dev/null
                  - '#sudo yum install jq mysql -y'
                  - !Join
                    - ''
                    - - DB_HOST=
                      - !GetAtt 'RDSCluster.Endpoint.Address'
                  - '# Retrieves & Assigns to Variables Admin DB Credentials'
                  - !Join
                    - ''
                    - - 'ADMIN_DB_SECRET=$(aws secretsmanager get-secret-value --secret-id '
                      - !Join
                        - '-'
                        - - !Select
                            - 0
                            - !Split
                              - '-'
                              - !Select
                                - 6
                                - !Split
                                  - ':'
                                  - !Ref 'RDSClusterAdminSecret'
                          - !Select
                            - 1
                            - !Split
                              - '-'
                              - !Select
                                - 6
                                - !Split
                                  - ':'
                                  - !Ref 'RDSClusterAdminSecret'
                      - ' --region '
                      - !Ref 'AWS::Region'
                      - ' | jq --raw-output .SecretString)'
                  - ADMIN_DB_USERNAME=$(jq -n -r --argjson data "$ADMIN_DB_SECRET"
                    '$data.username')
                  - export MYSQL_PWD=$(jq -n -r --argjson data "$ADMIN_DB_SECRET"
                    '$data.password')
                  - '# Retrieves & Assigns to Variables Non-Admin DB Credentials'
                  - !Join
                    - ''
                    - - 'NON_ADMIN_DB_SECRET=$(aws secretsmanager get-secret-value
                        --secret-id '
                      - !Join
                        - '-'
                        - - !Select
                            - 0
                            - !Split
                              - '-'
                              - !Select
                                - 6
                                - !Split
                                  - ':'
                                  - !Ref 'RDSClusterNonAdminSecret'
                          - !Select
                            - 1
                            - !Split
                              - '-'
                              - !Select
                                - 6
                                - !Split
                                  - ':'
                                  - !Ref 'RDSClusterNonAdminSecret'
                      - ' --region '
                      - !Ref 'AWS::Region'
                      - ' | jq --raw-output .SecretString)'
                  - NON_ADMIN_DB_USERNAME=$(jq -n -r --argjson data "$NON_ADMIN_DB_SECRET"
                    '$data.username')
                  - NON_ADMIN_DB_PASSWORD=$(jq -n -r --argjson data "$NON_ADMIN_DB_SECRET"
                    '$data.password')
                  - "echo \"\nDROP DATABASE IF EXISTS <database-name>;\n\nCREATE DATABASE\
                    \ <database-name>;\n\nUSE <database-name>;\n\n/* Deletes (if necessary)\
                    \ and Creates Non-Admin User */\nCREATE USER '$NON_ADMIN_DB_USERNAME'\
                    \ IDENTIFIED BY '$NON_ADMIN_DB_PASSWORD';\n\nCREATE TABLE sessions\
                    \ (\n  beginstring CHAR(8) NOT NULL,\n  sendercompid VARCHAR(64)\
                    \ NOT NULL,\n  targetcompid VARCHAR(64) NOT NULL,\n  session_qualifier\
                    \ VARCHAR(64) NOT NULL,\n  creation_time DATETIME NOT NULL,\n\
                    \  incoming_seqnum INT NOT NULL, \n  outgoing_seqnum INT NOT NULL,\n\
                    \  PRIMARY KEY (beginstring, sendercompid, targetcompid, session_qualifier)\n\
                    );\nGRANT SELECT, INSERT, UPDATE, DELETE ON <database-name>.sessions\
                    \ TO '$NON_ADMIN_DB_USERNAME';\n\nCREATE TABLE messages (\n  beginstring\
                    \ CHAR(8) NOT NULL,\n  sendercompid VARCHAR(64) NOT NULL,\n  targetcompid\
                    \ VARCHAR(64) NOT NULL,\n  session_qualifier VARCHAR(64) NOT NULL,\n\
                    \  msgseqnum INT NOT NULL, \n  message BLOB NOT NULL,\n  PRIMARY\
                    \ KEY (beginstring, sendercompid, targetcompid, session_qualifier,\
                    \ msgseqnum)\n);\nGRANT SELECT, INSERT, UPDATE, DELETE ON <database-name>.messages\
                    \ TO '$NON_ADMIN_DB_USERNAME';\n\nCREATE TABLE messages_log (\n\
                    \  id INT UNSIGNED NOT NULL AUTO_INCREMENT,\n  time DATETIME NOT\
                    \ NULL,\n  time_milliseconds INT NOT NULL,\n  beginstring CHAR(8),\n\
                    \  sendercompid VARCHAR(64),\n  targetcompid VARCHAR(64),\n  session_qualifier\
                    \ VARCHAR(64),\n  text BLOB NOT NULL,\n  PRIMARY KEY (id)\n);\n\
                    GRANT SELECT, INSERT, UPDATE, DELETE ON <database-name>.messages_log\
                    \ TO '$NON_ADMIN_DB_USERNAME';\n\nCREATE TABLE messages_backup_log\
                    \ (\n  id INT UNSIGNED NOT NULL AUTO_INCREMENT,\n  time DATETIME\
                    \ NOT NULL,\n  time_milliseconds INT NOT NULL,\n  beginstring\
                    \ CHAR(8),\n  sendercompid VARCHAR(64),\n  targetcompid VARCHAR(64),\n\
                    \  session_qualifier VARCHAR(64),\n  text BLOB NOT NULL,\n  PRIMARY\
                    \ KEY (id)\n);\nGRANT SELECT, INSERT, UPDATE, DELETE ON <database-name>.messages_backup_log\
                    \ TO '$NON_ADMIN_DB_USERNAME';\n\nCREATE TABLE event_log (\n \
                    \ id INT UNSIGNED NOT NULL AUTO_INCREMENT,\n  time DATETIME NOT\
                    \ NULL,\n  time_milliseconds INT NOT NULL,\n  beginstring CHAR(8),\n\
                    \  sendercompid VARCHAR(64),\n  targetcompid VARCHAR(64),\n  session_qualifier\
                    \ VARCHAR(64),\n  text BLOB NOT NULL,\n  PRIMARY KEY (id)\n);\n\
                    GRANT SELECT, INSERT, UPDATE, DELETE ON <database-name>.event_log\
                    \ TO '$NON_ADMIN_DB_USERNAME';\n\nCREATE TABLE event_backup_log\
                    \ (\n  id INT UNSIGNED NOT NULL AUTO_INCREMENT,\n  time DATETIME\
                    \ NOT NULL,\n  time_milliseconds INT NOT NULL,\n  beginstring\
                    \ CHAR(8),\n  sendercompid VARCHAR(64),\n  targetcompid VARCHAR(64),\n\
                    \  session_qualifier VARCHAR(64),\n  text BLOB NOT NULL,\n  PRIMARY\
                    \ KEY (id)\n);\nGRANT SELECT, INSERT, UPDATE, DELETE ON <database-name>.event_backup_log\
                    \ TO '$NON_ADMIN_DB_USERNAME';\n\nCREATE TABLE ActiveEngine  (\n\
                    \  TS TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n  ipAddress VARCHAR(16)\
                    \ NOT NULL,\n  PRIMARY KEY (TS, ipAddress)\n);\nGRANT SELECT,\
                    \ UPDATE ON <database-name>.ActiveEngine TO '$NON_ADMIN_DB_USERNAME';\n\
                    \nINSERT INTO ActiveEngine VALUES (NOW(), 'none');\n\nDELIMITER\
                    \ //\n\ncreate procedure EngineStatus(IN ipAdd varchar(16), OUT\
                    \ value int, OUT lastIpAdd varchar(16), OUT lastTimestamp DATETIME,\
                    \ OUT timeNow DATETIME, OUT timeDiffSec int)\nBEGIN\n\tSTART TRANSACTION;\n\
                    \    SET timeNow = NOW();\n    SELECT TS, timestampdiff (second,\
                    \ TS, timeNow), ipAddress INTO lastTimestamp, timeDiffSec, lastIpAdd\
                    \ FROM ActiveEngine;\n    IF timeDiffSec <= 3 AND ipAdd != lastIpAdd\
                    \ THEN            # If another IP is the leader and not stale\
                    \ \n      SET value = 0;                                     \
                    \      # Then I do nothing and keep waiting\n    ELSE \n     \
                    \ UPDATE ActiveEngine SET TS = timeNow, ipAddress = ipAdd; # Else\
                    \ I am going to be the leader (update DB to say this) \n     \
                    \ IF (timeDiffSec > 3) THEN                                # \
                    \  If the last leader is stale (no matter if it was me or another\
                    \ IP)\n        SET value = -1;                               \
                    \         #   Then I need to become the new leader\n      ELSE\n\
                    \        SET value = 1;                                      \
                    \   #   Else I am still the active leader\n      END IF;\n   \
                    \ END IF;\n    COMMIT;\nEND //\n\nDELIMITER ;\n\nGRANT SELECT\
                    \ ON mysql.proc TO '$NON_ADMIN_DB_USERNAME';\nGRANT EXECUTE ON\
                    \ PROCEDURE <database-name>.EngineStatus TO '$NON_ADMIN_DB_USERNAME';\n\
                    \n\" >> /tmp/rds-cluster-prep.sql"
                  - !Join
                    - ''
                    - - '#sudo sed -i ''s/<database-name>/`quickfix-'
                      - !Select
                        - 2
                        - !Split
                          - /
                          - !Ref 'AWS::StackId'
                      - '`/g'' /tmp/rds-cluster-prep.sql'
                  - !Join
                    - ''
                    - - sudo sed -i 's/<database-name>/`quickfix`/g' /tmp/rds-cluster-prep.sql
                  - !Join
                    - ''
                    - - mysql --user $ADMIN_DB_USERNAME --host $DB_HOST --ssl-mode
                        disabled --execute 'source /tmp/rds-cluster-prep.sql'
            name: CreateDBObjects
            onFailure: step:TerminateInstanceOnFailure
          - action: aws:executeAwsApi
            inputs:
              Api: TerminateInstances
              InstanceIds:
                - '{{LaunchInstance.InstanceIds}}'
              Service: ec2
            name: TerminateInstanceOnSuccess
            onFailure: step:SignalFailure
          - action: aws:executeAwsApi
            inputs:
              Api: SignalResource
              LogicalResourceId: RDSClusterInitializationWaiter
              Service: cloudformation
              StackName: !Ref 'AWS::StackName'
              Status: SUCCESS
              UniqueId: !Ref 'RDSCluster'
            isEnd: true
            name: SignalSuccess
            onFailure: step:SignalFailure
          - action: aws:executeAwsApi
            inputs:
              Api: TerminateInstances
              InstanceIds:
                - '{{LaunchInstance.InstanceIds}}'
              Service: ec2
            name: TerminateInstanceOnFailure
            onFailure: step:SignalFailure
          - action: aws:executeAwsApi
            inputs:
              Api: SignalResource
              LogicalResourceId: RDSClusterInitializationWaiter
              Service: cloudformation
              StackName: !Ref 'AWS::StackName'
              Status: FAILURE
              UniqueId: !Ref 'RDSCluster'
            isEnd: true
            name: SignalFailure
        parameters:
          ExecutionRoleArn:
            default: !GetAtt 'RDSClusterPrepExecutionRole.Arn'
            description: The service role to use for this automation.
            type: String
          LatestUbuntu2004AMIId:
            default: '{{ssm:/aws/service/canonical/ubuntu/server/20.04/stable/current/amd64/hvm/ebs-gp2/ami-id}}'
            description: The latest Ubuntu 20.04 LTS AMI queried from the public parameter.
            type: String
        schemaVersion: '0.3'
      DocumentType: Automation
    Type: AWS::SSM::Document
  RDSParameterGroup:
    Properties:
      Description: !Join
        - ''
        - - 'Parameter group for '
          - !Ref 'AWS::StackName'
          - ' stack'
      Family: aurora5.6
      Parameters:
        long_query_time: 5
        slow_query_log: 1
    Type: AWS::RDS::DBParameterGroup
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



