OMERO-cloudformation-templates/OMEROonECS_ALBwithTLS_RW.yaml [207:448]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Name: omeroserver
      NamespaceId: !Ref 'CloudMap'
  
  OMEROECSCluster:
    Type: AWS::ECS::Cluster
    Properties:
      ClusterName: !Sub ${AWS::StackName}-OMEROECSCluster
      ClusterSettings:
        - Name: containerInsights
          Value:  enabled
      Tags:
        - Key: project
          Value: omero-on-aws
  OMEROLoadBalancer:
    DependsOn:
      - LBAccessLogBucket
      - LBAccessLogBucketPolicy
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties:
      LoadBalancerAttributes:
        - Key: load_balancing.cross_zone.enabled
          Value: "true"
      Scheme: internet-facing
      Subnets:
        - !Ref 'PublicSubnet1Id'
        - !Ref 'PublicSubnet2Id'
      SecurityGroups:
        - !Ref LBSecurityGroup
      Tags:
        - Key: project
          Value: omero-on-aws
      Type: application
      LoadBalancerAttributes:
        - Key: access_logs.s3.enabled
          Value: true
        - Key: access_logs.s3.bucket
          Value: !Join
            - '-'
            - - !Ref LBAccessLogBucketName
              - !Ref Namespace
              - !Ref AWS::AccountId
  LBAccessLogBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Join
            - '-'
            - - !Ref LBAccessLogBucketName
              - !Ref Namespace
              - !Ref AWS::AccountId
      BucketEncryption:
        ServerSideEncryptionConfiguration:
          - ServerSideEncryptionByDefault:
              SSEAlgorithm: AES256
  LBAccessLogBucketPolicy:
    Type: AWS::S3::BucketPolicy
    Properties: 
      Bucket: !Ref LBAccessLogBucket
      PolicyDocument:
        Statement:
          - Action:
              - 's3:PutObject'
            Effect: Allow
            Resource: 
              - !Sub '${LBAccessLogBucket.Arn}/*'
            Principal: 
              AWS: !FindInMap [RegionELBAccountIdMap, !Ref 'AWS::Region', AccountId]
          - Action:
              - 's3:PutObject'
            Effect: Allow
            Resource: 
              - !Sub '${LBAccessLogBucket.Arn}/*'
            Principal: 
              Service: delivery.logs.amazonaws.com
            Condition:
              StringEquals:
                s3:x-amz-acl: bucket-owner-full-control
          - Action:
              - 's3:GetBucketAcl'
            Effect: Allow
            Resource: 
              - !Sub ${LBAccessLogBucket.Arn}
            Principal: 
              Service: delivery.logs.amazonaws.com
  LogGroup:
    Type: AWS::Logs::LogGroup
    Properties:
      LogGroupName: !Sub /ecs/omero/${AWS::StackName}
  
  MountTarget:
    Type: AWS::EFS::MountTarget
    Properties:
      FileSystemId: !Ref EFSFileSystem
      SubnetId: !Ref PrivateSubnet1Id
      SecurityGroups:
        - !Ref EFSSecurityGroup
  NFSAccessPoint:
    Type: AWS::EFS::AccessPoint
    Properties: 
      FileSystemId: !Ref EFSFileSystem
      PosixUser:
        Gid: "0"
        Uid: "0"
      RootDirectory:
        Path: "/"

  OmeroserverService:
    Type: AWS::ECS::Service
    DependsOn:
      - OmeroserverTaskDefinition
    Properties:
      Cluster: !Ref 'OMEROECSCluster'
      DeploymentConfiguration:
        MaximumPercent: 200
        MinimumHealthyPercent: 100
      DeploymentController:
        Type: ECS
      DesiredCount: 1
      LaunchType: !If
        - runContainerOnEC2
        - 'EC2'
        - 'FARGATE'
      EnableExecuteCommand: true
      NetworkConfiguration:
        AwsvpcConfiguration:
          AssignPublicIp: DISABLED
          SecurityGroups:
            - !Ref OmeroSecurityGroup
          Subnets:
            - !Ref 'PrivateSubnet1Id'
      PropagateTags: SERVICE
      SchedulingStrategy: REPLICA
      ServiceRegistries:
        - RegistryArn: !GetAtt 'OmeroserverServiceDiscoveryEntry.Arn'
      Tags:
        - Key: project
          Value: omero-on-aws
        - Key: service
          Value: omeroserver
      TaskDefinition: !Ref 'OmeroserverTaskDefinition'
  
  OmeroserverTaskDefinition:
    Type: AWS::ECS::TaskDefinition
    Properties:
      ContainerDefinitions:
        - Environment:
            - Name: CONFIG_omero_db_host
              Value: !Ref RDSEndpointAddress
            - Name: CONFIG_omero_db_user
              Value: !Ref DBUser
            - Name: CONFIG_omero_db_pass
              Value: !Join ['', ['{{resolve:secretsmanager:', !Ref RDSDatabaseSecret, ':SecretString:password}}' ]]
            - Name: CONFIG_omero_db_name
              Value: omero
            - Name: LOCALDOMAIN
              Value: !Join
                - ''
                - - !Ref 'AWS::Region'
                  - .compute.internal
                  - 'omero.local'
            - Name: ROOTPASS
              Value: omero
          Essential: true
          Image: !Ref OMEROServerContainerImage
          LinuxParameters: { initProcessEnabled: true }
          LogConfiguration:
            LogDriver: awslogs
            Options:
              awslogs-group: !Ref 'LogGroup'
              awslogs-region: !Ref 'AWS::Region'
              awslogs-stream-prefix: omeroserver
          Name: omeroserver
          MountPoints:
            - ContainerPath: /OMERO
              SourceVolume: my-efs
          PortMappings:
            - ContainerPort: 4063
              HostPort: 4063
              Protocol: tcp
            - ContainerPort: 4064
              HostPort: 4064
              Protocol: tcp
      Volumes:
        - name: my-efs
          EFSVolumeConfiguration: 
            FilesystemId: !Ref EFSFileSystem
            TransitEncryption: ENABLED
            AuthorizationConfig: 
              AccessPointId: !Ref NFSAccessPoint
              IAM: ENABLED
      Cpu: !Ref OMEROServerContainerCPU
      Memory: !Ref OMEROServerContainerMemory
      ExecutionRoleArn: !Ref 'OmeroserverTaskExecutionRole'
      TaskRoleArn: !Ref 'OmeroserverTaskRole'
      Family: omero-server
      NetworkMode: awsvpc
      RequiresCompatibilities:
        - !If
          - runContainerOnEC2
          - 'EC2'
          - 'FARGATE'
  OmeroserverTaskExecutionRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action:
              - sts:AssumeRole
            Effect: Allow
            Principal:
              Service: ecs-tasks.amazonaws.com
        Version: '2012-10-17'
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy
        - arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
      Tags:
      - Key: project
        Value: omero-on-aws
      - Key: service
        Value: omeroserver
  OmeroserverTaskRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action:
              - sts:AssumeRole
            Effect: Allow
            Principal:
              Service: ecs-tasks.amazonaws.com
        Version: '2012-10-17'
      Policies:
        - PolicyName: OmeroserverOmeroVolumeMountPolicy
          PolicyDocument:
            Statement:
              - Action:
                  - elasticfilesystem:ClientMount
                  - elasticfilesystem:ClientWrite
                  - elasticfilesystem:ClientRootAccess
                Condition:
                  StringEquals:
                    elasticfilesystem:AccessPointArn: !Ref NFSAccessPoint
                Effect: Allow
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



OMERO-cloudformation-templates/OMEROonECS_RW.yaml [197:438]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Name: omeroserver
      NamespaceId: !Ref 'CloudMap'
  
  OMEROECSCluster:
    Type: AWS::ECS::Cluster
    Properties:
      ClusterName: !Sub ${AWS::StackName}-OMEROECSCluster
      ClusterSettings:
        - Name: containerInsights
          Value:  enabled
      Tags:
        - Key: project
          Value: omero-on-aws
  OMEROLoadBalancer:
    DependsOn:
      - LBAccessLogBucket
      - LBAccessLogBucketPolicy
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties:
      LoadBalancerAttributes:
        - Key: load_balancing.cross_zone.enabled
          Value: "true"
      Scheme: internet-facing
      Subnets:
        - !Ref 'PublicSubnet1Id'
        - !Ref 'PublicSubnet2Id'
      SecurityGroups:
        - !Ref LBSecurityGroup
      Tags:
        - Key: project
          Value: omero-on-aws
      Type: application
      LoadBalancerAttributes:
        - Key: access_logs.s3.enabled
          Value: true
        - Key: access_logs.s3.bucket
          Value: !Join
            - '-'
            - - !Ref LBAccessLogBucketName
              - !Ref Namespace
              - !Ref AWS::AccountId
  LBAccessLogBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Join
            - '-'
            - - !Ref LBAccessLogBucketName
              - !Ref Namespace
              - !Ref AWS::AccountId
      BucketEncryption:
        ServerSideEncryptionConfiguration:
          - ServerSideEncryptionByDefault:
              SSEAlgorithm: AES256
  LBAccessLogBucketPolicy:
    Type: AWS::S3::BucketPolicy
    Properties: 
      Bucket: !Ref LBAccessLogBucket
      PolicyDocument:
        Statement:
          - Action:
              - 's3:PutObject'
            Effect: Allow
            Resource: 
              - !Sub '${LBAccessLogBucket.Arn}/*'
            Principal: 
              AWS: !FindInMap [RegionELBAccountIdMap, !Ref 'AWS::Region', AccountId]
          - Action:
              - 's3:PutObject'
            Effect: Allow
            Resource: 
              - !Sub '${LBAccessLogBucket.Arn}/*'
            Principal: 
              Service: delivery.logs.amazonaws.com
            Condition:
              StringEquals:
                s3:x-amz-acl: bucket-owner-full-control
          - Action:
              - 's3:GetBucketAcl'
            Effect: Allow
            Resource: 
              - !Sub ${LBAccessLogBucket.Arn}
            Principal: 
              Service: delivery.logs.amazonaws.com
  LogGroup:
    Type: AWS::Logs::LogGroup
    Properties:
      LogGroupName: !Sub /ecs/omero/${AWS::StackName}
  
  MountTarget:
    Type: AWS::EFS::MountTarget
    Properties:
      FileSystemId: !Ref EFSFileSystem
      SubnetId: !Ref PrivateSubnet1Id
      SecurityGroups:
        - !Ref EFSSecurityGroup
  NFSAccessPoint:
    Type: AWS::EFS::AccessPoint
    Properties: 
      FileSystemId: !Ref EFSFileSystem
      PosixUser:
        Gid: "0"
        Uid: "0"
      RootDirectory:
        Path: "/"

  OmeroserverService:
    Type: AWS::ECS::Service
    DependsOn:
      - OmeroserverTaskDefinition
    Properties:
      Cluster: !Ref 'OMEROECSCluster'
      DeploymentConfiguration:
        MaximumPercent: 200
        MinimumHealthyPercent: 100
      DeploymentController:
        Type: ECS
      DesiredCount: 1
      LaunchType: !If
        - runContainerOnEC2
        - 'EC2'
        - 'FARGATE'
      EnableExecuteCommand: true
      NetworkConfiguration:
        AwsvpcConfiguration:
          AssignPublicIp: DISABLED
          SecurityGroups:
            - !Ref OmeroSecurityGroup
          Subnets:
            - !Ref 'PrivateSubnet1Id'
      PropagateTags: SERVICE
      SchedulingStrategy: REPLICA
      ServiceRegistries:
        - RegistryArn: !GetAtt 'OmeroserverServiceDiscoveryEntry.Arn'
      Tags:
        - Key: project
          Value: omero-on-aws
        - Key: service
          Value: omeroserver
      TaskDefinition: !Ref 'OmeroserverTaskDefinition'
  
  OmeroserverTaskDefinition:
    Type: AWS::ECS::TaskDefinition
    Properties:
      ContainerDefinitions:
        - Environment:
            - Name: CONFIG_omero_db_host
              Value: !Ref RDSEndpointAddress
            - Name: CONFIG_omero_db_user
              Value: !Ref DBUser
            - Name: CONFIG_omero_db_pass
              Value: !Join ['', ['{{resolve:secretsmanager:', !Ref RDSDatabaseSecret, ':SecretString:password}}' ]]
            - Name: CONFIG_omero_db_name
              Value: omero
            - Name: LOCALDOMAIN
              Value: !Join
                - ''
                - - !Ref 'AWS::Region'
                  - .compute.internal
                  - 'omero.local'
            - Name: ROOTPASS
              Value: omero
          Essential: true
          Image: !Ref OMEROServerContainerImage
          LinuxParameters: { initProcessEnabled: true }
          LogConfiguration:
            LogDriver: awslogs
            Options:
              awslogs-group: !Ref 'LogGroup'
              awslogs-region: !Ref 'AWS::Region'
              awslogs-stream-prefix: omeroserver
          Name: omeroserver
          MountPoints:
            - ContainerPath: /OMERO
              SourceVolume: my-efs
          PortMappings:
            - ContainerPort: 4063
              HostPort: 4063
              Protocol: tcp
            - ContainerPort: 4064
              HostPort: 4064
              Protocol: tcp
      Volumes:
        - name: my-efs
          EFSVolumeConfiguration: 
            FilesystemId: !Ref EFSFileSystem
            TransitEncryption: ENABLED
            AuthorizationConfig: 
              AccessPointId: !Ref NFSAccessPoint
              IAM: ENABLED
      Cpu: !Ref OMEROServerContainerCPU
      Memory: !Ref OMEROServerContainerMemory
      ExecutionRoleArn: !Ref 'OmeroserverTaskExecutionRole'
      TaskRoleArn: !Ref 'OmeroserverTaskRole'
      Family: omero-server
      NetworkMode: awsvpc
      RequiresCompatibilities:
        - !If
          - runContainerOnEC2
          - 'EC2'
          - 'FARGATE'
  OmeroserverTaskExecutionRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action:
              - sts:AssumeRole
            Effect: Allow
            Principal:
              Service: ecs-tasks.amazonaws.com
        Version: '2012-10-17'
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy
        - arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
      Tags:
      - Key: project
        Value: omero-on-aws
      - Key: service
        Value: omeroserver
  OmeroserverTaskRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action:
              - sts:AssumeRole
            Effect: Allow
            Principal:
              Service: ecs-tasks.amazonaws.com
        Version: '2012-10-17'
      Policies:
        - PolicyName: OmeroserverOmeroVolumeMountPolicy
          PolicyDocument:
            Statement:
              - Action:
                  - elasticfilesystem:ClientMount
                  - elasticfilesystem:ClientWrite
                  - elasticfilesystem:ClientRootAccess
                Condition:
                  StringEquals:
                    elasticfilesystem:AccessPointArn: !Ref NFSAccessPoint
                Effect: Allow
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



