Amazon AWS CloudFormation Template

In order to provide a redundant proxy configuration, the following guide can be followed.

Note: Support for this template is exclusively provided for Heimdall Enterprise Edition customers as customers that require this level of redundancy also typically require 24/7 support. Heimdall offers private offer pricing to customers on a negotiated basis if needed. The AMI ID provided below is the current Enterprise AMI ID that is available, however the current AMI ID may change over time. To find the current Enterprise AMI, please search in the "community ami" section of the EC2 launcher, and search for the string "5d2be2df-c328-4d9b-8d6e-badc5705e9a7". This will provide the current marketplace AMI ID to use, i.e.:

Here, the AMI ID to use is: ami-06b8b11db8101d023

If none are found, ensure that you have subscribed to the Heimdall Enterprise Edition offering in the AWS Marketplace, as it may be hidden until subscribed.

The resources created by this template are:

It depends on: * Existing VPC & Subnets * An existing Heimdall Central Manager * SSH Key

All resources will be named based on the stack name as appropriate, and their creation can be reversed by deleting the stack.

Heimdall assumes no responsibility for the charges that may be charged by AWS through the use of this template, as in particular, ouside of the EC2 instances, the network load balancer may incure charges, as explained "here".

AWSTemplateFormatVersion: 2010-09-09
Parameters:
  HeimdallProxyAMIID:
    Type: String
    Default: ami-0496a2e9f2d6890ec
    Description: The Enterprise Edition AMI ID to use
  HeimdallProxyVPC:
    Type: 'AWS::EC2::VPC::Id'
    Description: >-
      VPC ID for Proxy Use, should generally match the database's VPC being
      accessed
  HeimdallProxyAvailabilityZones:
    Type: 'List<AWS::EC2::AvailabilityZone::Name>'
    Description: Availability zones for NLB Deployment
  HeimdallProxySubnetList:
    Type: 'List<AWS::EC2::Subnet::Id>'
    Description: >-
      Subnet IDs for ELB for Proxy Deployment (ensure to match the AZ's and
      availability zones selected)
  hdHost:
    Type: String
    Description: >-
      Private Hostname of Heimdall Central Manager, do not use the public
      hostname if present
  hdUser:
    Type: String
    Default: admin
    Description: Central Manager Username OR proxy access key from vdb configuration
  hdPassword:
    Type: String
    Description: Central Manager Password OR proxy secret key from vdb configuration
  vdbName:
    Type: String
    Description: VDB Name configured in central manager
  ProxyPort:
    Description: Database Proxy port
    Type: Number
    Default: 5432
    ConstraintDescription: >-
      Provide the port the proxies are expected to run on (typically the same as
      the back-end database, i.e. 3306 for mysql, 5432 for postgres, or 1433 for
      SQL Server), needed to create a security group for the proxies
  ProxyMinimum:
    Description: Minimum number of proxies
    Type: Number
    Default: 2
    ConstraintDescription: How many proxies should be in operation at minimum
  ProxyMaximum:
    Description: Maximum number of proxies
    Type: Number
    Default: 4
    ConstraintDescription: How many proxies should be in operation at most
  InstanceTypeParameterProxy:
    Type: String
    Default: c5.xlarge
    AllowedValues:
      - t3.medium
      - c5.large
      - c5.xlarge
      - c5.2xlarge
      - c5.4xlarge
    Description: Enter Proxy instance type (autoscaling)
  KeyName:
    Description: Name of an existing EC2 KeyPair to enable SSH access to the instance
    Type: 'AWS::EC2::KeyPair::KeyName'
    ConstraintDescription: must be the name of an existing EC2 KeyPair.
Metadata:
  Generator: ''
  'AWS::CloudFormation::Designer':
    d2b3fbb5-c87c-490d-b0ff-5c0804f855f0:
      size:
        width: 60
        height: 60
      position:
        x: 630
        'y': 450
      z: 1
      embeds: []
    dc671d3b-807c-4ea9-b368-7e3d534e22e1:
      size:
        width: 60
        height: 60
      position:
        x: 630
        'y': 330
      z: 1
      embeds: []
    5311a68f-b7ab-48e1-b1d7-9038174cf489:
      size:
        width: 60
        height: 60
      position:
        x: 530
        'y': 330
      z: 1
      embeds: []
      isassociatedwith:
        - 0e9f449e-767d-4419-aac9-2e7fe29f4fd4
        - dc671d3b-807c-4ea9-b368-7e3d534e22e1
    fbdc2e18-b910-405e-aeed-433c01a5a71b:
      size:
        width: 60
        height: 60
      position:
        x: 530
        'y': 450
      z: 1
      embeds: []
      isassociatedwith:
        - d2b3fbb5-c87c-490d-b0ff-5c0804f855f0
    34e5960d-26f6-4d11-aae1-85c02c36b986:
      size:
        width: 60
        height: 60
      position:
        x: 420
        'y': 450
      z: 1
      embeds: []
      isassociatedwith:
        - fbdc2e18-b910-405e-aeed-433c01a5a71b
        - ded7f98f-10d3-4e44-a367-bd3cb1ea347e
    ded7f98f-10d3-4e44-a367-bd3cb1ea347e:
      size:
        width: 60
        height: 60
      position:
        x: 420
        'y': 310
      z: 1
      embeds: []
    57399634-3282-4398-94cd-e5b1ab3455bf:
      size:
        width: 60
        height: 60
      position:
        x: 220
        'y': 310
      z: 1
      embeds: []
    f5ca956b-6572-44a5-99d9-17899f5a826a:
      size:
        width: 60
        height: 60
      position:
        x: 320
        'y': 310
      z: 1
      embeds: []
      isassociatedwith:
        - 57399634-3282-4398-94cd-e5b1ab3455bf
    662a6ed5-4d47-488d-89b0-4ff2eba99817:
      size:
        width: 60
        height: 60
      position:
        x: 220
        'y': 490
      z: 1
      embeds: []
      isassociatedwith:
        - 34e5960d-26f6-4d11-aae1-85c02c36b986
    fbb5ee8e-a3ea-4616-a3ab-bf77a0f0f012:
      size:
        width: 60
        height: 60
      position:
        x: 320
        'y': 500
      z: 1
      embeds: []
    a91d43f5-bb88-4305-8220-8621e84771a4:
      size:
        width: 60
        height: 60
      position:
        x: 220
        'y': 400
      z: 1
      embeds: []
      isassociatedwith:
        - 34e5960d-26f6-4d11-aae1-85c02c36b986
    f13bafeb-8014-489d-a066-9910c4554ee2:
      size:
        width: 60
        height: 60
      position:
        x: 320
        'y': 400
      z: 1
      embeds: []
Description: HA Template for Heimdall Data Access Platform
Resources:
  HeimdallProxyIAM:
    Type: 'AWS::IAM::Role'
    Properties:
      Path: /
      AssumeRolePolicyDocument: >-
        {"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"ec2.amazonaws.com"},"Action":"sts:AssumeRole"}]}
      MaxSessionDuration: 3600
      RoleName: !Join 
        - '-'
        - - !Ref 'AWS::StackName'
          - proxy
      ManagedPolicyArns:
        - 'arn:aws:iam::aws:policy/CloudWatchFullAccess'
      Tags:
        - Key: Name
          Value: !Join 
            - '-'
            - - !Ref 'AWS::StackName'
              - proxy
    Metadata:
      'AWS::CloudFormation::Designer':
        id: dc671d3b-807c-4ea9-b368-7e3d534e22e1
  HeimdallProxyIAMInstanceProfile:
    Type: 'AWS::IAM::InstanceProfile'
    Properties:
      Path: /
      Roles:
        - !Ref HeimdallProxyIAM
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 5311a68f-b7ab-48e1-b1d7-9038174cf489
  HeimdallProxySecurityGroup:
    Type: 'AWS::EC2::SecurityGroup'
    Properties:
      GroupName: !Join 
        - '-'
        - - !Ref 'AWS::StackName'
          - proxySG
      GroupDescription: Security group for Heimdall Proxy
      VpcId: !Ref HeimdallProxyVPC
      SecurityGroupIngress:
        - IpProtocol: tcp
          CidrIp: 0.0.0.0/0
          FromPort: 22
          ToPort: 22
        - IpProtocol: tcp
          CidrIp: 0.0.0.0/0
          FromPort: !Ref ProxyPort
          ToPort: !Ref ProxyPort
      Tags:
        - Key: Name
          Value: !Join 
            - '-'
            - - !Ref 'AWS::StackName'
              - proxy
    Metadata:
      'AWS::CloudFormation::Designer':
        id: d2b3fbb5-c87c-490d-b0ff-5c0804f855f0
  ProxyLaunchConfig:
    Type: 'AWS::AutoScaling::LaunchConfiguration'
    Properties:
      AssociatePublicIpAddress: false
      IamInstanceProfile: !Ref HeimdallProxyIAMInstanceProfile
      ImageId: !Ref HeimdallProxyAMIID
      InstanceMonitoring: true
      InstanceType: !Ref InstanceTypeParameterProxy
      KeyName: !Ref KeyName
      SecurityGroups:
        - !Ref HeimdallProxySecurityGroup
      LaunchConfigurationName: !Join 
        - '-'
        - - !Ref 'AWS::StackName'
          - proxy
      UserData: !Base64 
        'Fn::Join':
          - ''
          - - |-
              #!/bin/bash
              echo "
            - vdbName=
            - !Ref vdbName
            - |-

              hdRole=proxy
            - |-

              hdHost=
            - !Ref hdHost
            - |-

              hdPort=8087
            - |-

              hdUser=
            - !Ref hdUser
            - |-

              hdPassword=
            - !Ref hdPassword
            - |-

              " > /etc/heimdall.conf
    Metadata:
      'AWS::CloudFormation::Designer':
        id: fbdc2e18-b910-405e-aeed-433c01a5a71b
  HeimdallProxyAutoScalingGroup:
    Type: 'AWS::AutoScaling::AutoScalingGroup'
    Version: 2020-04-22
    Properties:
      AvailabilityZones: !Ref HeimdallProxyAvailabilityZones
      VPCZoneIdentifier: !Ref HeimdallProxySubnetList
      LaunchConfigurationName: !Ref ProxyLaunchConfig
      TargetGroupARNs:
        - !Ref HeimdallProxyTargetGroup
      MinSize: !Ref ProxyMinimum
      MaxSize: !Ref ProxyMaximum
      Tags:
        - Key: Name
          Value: !Join 
            - '-'
            - - !Ref 'AWS::StackName'
              - proxy
          PropagateAtLaunch: true
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 34e5960d-26f6-4d11-aae1-85c02c36b986
  HeimdallProxyTargetGroup:
    Type: 'AWS::ElasticLoadBalancingV2::TargetGroup'
    Properties:
      Port: !Ref ProxyPort
      Protocol: TCP
      VpcId: !Ref HeimdallProxyVPC
      TargetGroupAttributes:
        - Key: deregistration_delay.timeout_seconds
          Value: 60
      Tags:
        - Key: Name
          Value: !Join 
            - '-'
            - - !Ref 'AWS::StackName'
              - proxy
    Metadata:
      'AWS::CloudFormation::Designer':
        id: ded7f98f-10d3-4e44-a367-bd3cb1ea347e
  HeimdallProxyLoadBalancer:
    Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
    Properties:
      Scheme: internal
      Type: network
      Subnets: !Ref HeimdallProxySubnetList
      Tags:
        - Key: Name
          Value: !Join 
            - '-'
            - - !Ref 'AWS::StackName'
              - proxy
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 57399634-3282-4398-94cd-e5b1ab3455bf
  HeimdallProxyLoadBalancerListener:
    Type: 'AWS::ElasticLoadBalancingV2::Listener'
    Properties:
      DefaultActions:
        - Type: forward
          TargetGroupArn: !Ref HeimdallProxyTargetGroup
      LoadBalancerArn: !Ref HeimdallProxyLoadBalancer
      Port: !Ref ProxyPort
      Protocol: TCP
    Metadata:
      'AWS::CloudFormation::Designer':
        id: f5ca956b-6572-44a5-99d9-17899f5a826a
  HeimdallProxyScaleUpPolicy:
    Type: 'AWS::AutoScaling::ScalingPolicy'
    Properties:
      AdjustmentType: ChangeInCapacity
      AutoScalingGroupName: !Ref HeimdallProxyAutoScalingGroup
      Cooldown: '60'
      ScalingAdjustment: '1'
    Metadata:
      'AWS::CloudFormation::Designer':
        id: a91d43f5-bb88-4305-8220-8621e84771a4
  HeimdallProxyScaleDownPolicy:
    Type: 'AWS::AutoScaling::ScalingPolicy'
    Properties:
      AdjustmentType: ChangeInCapacity
      AutoScalingGroupName: !Ref HeimdallProxyAutoScalingGroup
      Cooldown: '60'
      ScalingAdjustment: '-1'
    Metadata:
      'AWS::CloudFormation::Designer':
        id: 662a6ed5-4d47-488d-89b0-4ff2eba99817
  HeimdallProxyCPUAlarmHigh:
    Type: 'AWS::CloudWatch::Alarm'
    Properties:
      AlarmDescription: Scale-up if CPU > 65% for 3 minutes
      MetricName: CPUUtilization
      Namespace: AWS/EC2
      Statistic: Average
      Period: '60'
      EvaluationPeriods: '3'
      Threshold: '65'
      AlarmActions:
        - !Ref HeimdallProxyScaleUpPolicy
      Dimensions:
        - Name: AutoScalingGroupName
          Value: !Ref HeimdallProxyAutoScalingGroup
      ComparisonOperator: GreaterThanThreshold
    Metadata:
      'AWS::CloudFormation::Designer':
        id: f13bafeb-8014-489d-a066-9910c4554ee2
  HeimdallProxyCPUAlarmLow:
    Type: 'AWS::CloudWatch::Alarm'
    Properties:
      AlarmDescription: Scale-down if CPU < 40% for 6 minutes
      MetricName: CPUUtilization
      Namespace: AWS/EC2
      Statistic: Average
      Period: '60'
      EvaluationPeriods: '6'
      Threshold: '40'
      AlarmActions:
        - !Ref HeimdallProxyScaleDownPolicy
      Dimensions:
        - Name: AutoScalingGroupName
          Value: !Ref HeimdallProxyAutoScalingGroup
      ComparisonOperator: LessThanThreshold
    Metadata:
      'AWS::CloudFormation::Designer':
        id: fbb5ee8e-a3ea-4616-a3ab-bf77a0f0f012
Outputs:
  LoadBalancerUrl:
    Description: The hostname for load balanced db access
    Value: !GetAtt 
      - HeimdallProxyLoadBalancer
      - DNSName