dcm4chee/dcm4chee-arc-ec2-psql-keycloak.yml [952:1013]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      LaunchConfigurationName: !Ref 'ContainerInstances'
      MinSize: '1'
      MaxSize: '4'
      DesiredCapacity: !Ref EC2InstanceCount
    CreationPolicy:
      ResourceSignal:
        Timeout: PT15M
    UpdatePolicy:
      AutoScalingReplacingUpdate:
        WillReplace: 'true'
  ContainerInstances:
    Type: AWS::AutoScaling::LaunchConfiguration
    Properties:
      ImageId: !FindInMap [AWSRegionToAMI, !Ref 'AWS::Region', AMIID]
      SecurityGroups:
            - !Ref DefaultSecurityGroup
      InstanceType: !Ref 'InstanceType'
      IamInstanceProfile: !Ref 'EC2InstanceProfile'
      KeyName: !Ref 'KeyName'
      UserData:
        Fn::Base64: !Sub |
          #!/bin/bash -xe
          echo ECS_CLUSTER=${DCM4CHEECluster} >> /etc/ecs/ecs.config
          yum install -y aws-cfn-bootstrap bzip2 unzip git jq wget telnet java-11-amazon-corretto-headless
          /opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource ECSAutoScalingGroup --region ${AWS::Region}
          amazon-linux-extras install postgresql11 -y
          curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"  
          unzip awscliv2.zip  
          ./aws/install
          git clone https://github.com/dcm4che-dockerfiles/postgres-dcm4chee.git
          password=`aws secretsmanager get-secret-value --secret-id ${RDSDatabaseSecret} --query SecretString --output text | jq -r .password`
          PGPASSWORD=$password psql -h ${RDSInstance.Endpoint.Address} -U ${RDSDBUserName} -d pacsdb < postgres-dcm4chee/docker-entrypoint-initdb.d/10_create-psql.sql
          PGPASSWORD=$password psql -h ${RDSInstance.Endpoint.Address} -U ${RDSDBUserName} -d pacsdb < postgres-dcm4chee/docker-entrypoint-initdb.d/20_create-fk-index.sql
          PGPASSWORD=$password psql -h ${RDSInstance.Endpoint.Address} -U ${RDSDBUserName} -d pacsdb < postgres-dcm4chee/docker-entrypoint-initdb.d/30_create-case-insensitive-index.sql
          wget https://sourceforge.net/projects/dcm4che/files/dcm4che3/5.23.2/dcm4che-5.23.2-bin.zip -P /tmp
  EC2Role:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - ec2.amazonaws.com
            Action:
              - sts:AssumeRole
      Path: /
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role
        - arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
        - arn:aws:iam::aws:policy/AmazonS3FullAccess
        - arn:aws:iam::aws:policy/SecretsManagerReadWrite
      Tags:
      - Key: project
        Value: dcm4chee-arc-psql
      - Key: service
        Value: arc
  EC2InstanceProfile:
    Type: AWS::IAM::InstanceProfile
    Properties:
      Path: /
      Roles: [!Ref 'EC2Role']
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



dcm4chee/dcm4chee-arc-ec2-psql.yml [830:891]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      LaunchConfigurationName: !Ref 'ContainerInstances'
      MinSize: '1'
      MaxSize: '4'
      DesiredCapacity: !Ref EC2InstanceCount
    CreationPolicy:
      ResourceSignal:
        Timeout: PT15M
    UpdatePolicy:
      AutoScalingReplacingUpdate:
        WillReplace: 'true'
  ContainerInstances:
    Type: AWS::AutoScaling::LaunchConfiguration
    Properties:
      ImageId: !FindInMap [AWSRegionToAMI, !Ref 'AWS::Region', AMIID]
      SecurityGroups:
            - !Ref DefaultSecurityGroup
      InstanceType: !Ref 'InstanceType'
      IamInstanceProfile: !Ref 'EC2InstanceProfile'
      KeyName: !Ref 'KeyName'
      UserData:
        Fn::Base64: !Sub |
          #!/bin/bash -xe
          echo ECS_CLUSTER=${DCM4CHEECluster} >> /etc/ecs/ecs.config
          yum install -y aws-cfn-bootstrap bzip2 unzip git jq wget telnet java-11-amazon-corretto-headless
          /opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource ECSAutoScalingGroup --region ${AWS::Region}
          amazon-linux-extras install postgresql11 -y
          curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"  
          unzip awscliv2.zip  
          ./aws/install
          git clone https://github.com/dcm4che-dockerfiles/postgres-dcm4chee.git
          password=`aws secretsmanager get-secret-value --secret-id ${RDSDatabaseSecret} --query SecretString --output text | jq -r .password`
          PGPASSWORD=$password psql -h ${RDSInstance.Endpoint.Address} -U ${RDSDBUserName} -d pacsdb < postgres-dcm4chee/docker-entrypoint-initdb.d/10_create-psql.sql
          PGPASSWORD=$password psql -h ${RDSInstance.Endpoint.Address} -U ${RDSDBUserName} -d pacsdb < postgres-dcm4chee/docker-entrypoint-initdb.d/20_create-fk-index.sql
          PGPASSWORD=$password psql -h ${RDSInstance.Endpoint.Address} -U ${RDSDBUserName} -d pacsdb < postgres-dcm4chee/docker-entrypoint-initdb.d/30_create-case-insensitive-index.sql
          wget https://sourceforge.net/projects/dcm4che/files/dcm4che3/5.23.2/dcm4che-5.23.2-bin.zip -P /tmp
  EC2Role:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - ec2.amazonaws.com
            Action:
              - sts:AssumeRole
      Path: /
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role
        - arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
        - arn:aws:iam::aws:policy/AmazonS3FullAccess
        - arn:aws:iam::aws:policy/SecretsManagerReadWrite
      Tags:
      - Key: project
        Value: dcm4chee-arc-psql
      - Key: service
        Value: arc
  EC2InstanceProfile:
    Type: AWS::IAM::InstanceProfile
    Properties:
      Path: /
      Roles: [!Ref 'EC2Role']
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



