static/Reliability/Common/Code/CloudFormation/staticwebapp-active-passive.yaml [131:267]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Resources:

  DynamoDBServiceMockTable:
    Type: 'AWS::DynamoDB::Table'
    Properties: 
      TableName: 'RecommendationService'
      AttributeDefinitions: 
        - 
          AttributeName: 'ServiceAPI'
          AttributeType: 'S'
        - 
          AttributeName: 'UserID'
          AttributeType: 'N'
      KeySchema: 
        - 
          AttributeName: 'ServiceAPI'
          KeyType: 'HASH'
        - 
          AttributeName: 'UserID'
          KeyType: 'RANGE'
      ProvisionedThroughput: 
        ReadCapacityUnits: '5'
        WriteCapacityUnits: '5'
      SSESpecification: 
        SSEEnabled: 'true'

  ALB1SecurityGroup:
    Type: 'AWS::EC2::SecurityGroup'
    Properties:
      GroupDescription: >-
        Enable HTTP access via port 80 and 443 to the allowed CIDR
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: '80'
          ToPort: '80'
          CidrIp: !Ref ALBSGSource
        - IpProtocol: tcp
          FromPort: '443'
          ToPort: '443'
          CidrIp: !Ref ALBSGSource
      Tags:
        - Key: Name
          Value: !Join
            - '-'
            - - !Ref NamingPrefix
              - Load Balancer
      VpcId:
        Fn::ImportValue: !Sub '${VPCImportName}'

  ALB1LoadBalancer:
    Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
    #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticloadbalancingv2-loadbalancer.html
    Properties:
      SecurityGroups:
        - Ref: ALB1SecurityGroup
      Subnets:
        - Fn::ImportValue: !Sub '${VPCImportName}-${VPCImportALB1Subnet1}'
        - Fn::ImportValue: !Sub '${VPCImportName}-${VPCImportALB1Subnet2}'
        - Fn::ImportValue: !Sub '${VPCImportName}-${VPCImportALB1Subnet3}'

  ALB1Listener:
    Type: 'AWS::ElasticLoadBalancingV2::Listener'
    #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticloadbalancingv2-listener.html
    Properties:
      #  Certificates:
        #- Certificate
      DefaultActions:
        - Type: forward
          TargetGroupArn: !Ref ALB1TargetGroup
      LoadBalancerArn: !Ref ALB1LoadBalancer
      Port: '80'
      Protocol: HTTP

  ALB1TargetGroup:
    Type: 'AWS::ElasticLoadBalancingV2::TargetGroup'
    #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticloadbalancingv2-targetgroup.html
    Properties:
      HealthCheckPath: /healthcheck
      HealthCheckIntervalSeconds: 15
      #HealthCheckPort: 
      #HealthCheckProtocol:
      HealthCheckTimeoutSeconds: 3
      HealthyThresholdCount: 2
      Port: 80
      Protocol: HTTP
      # A short drain time helps speed up the lab
      TargetGroupAttributes:
        - Key: deregistration_delay.timeout_seconds
          Value: 10
      UnhealthyThresholdCount: 3
      VpcId: 
        Fn::ImportValue: !Sub '${VPCImportName}'

  Web1InstanceSecurityGroup:
    Type: 'AWS::EC2::SecurityGroup'
    Properties:
      GroupDescription: >-
        Enable HTTP access via port 80 and 443 restricted to the load balancer
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: '80'
          ToPort: '80'
          SourceSecurityGroupId: !Select 
            - 0
            - !GetAtt 
              - ALB1LoadBalancer
              - SecurityGroups
        - IpProtocol: tcp
          FromPort: '443'
          ToPort: '443'
          SourceSecurityGroupId: !Select 
            - 0
            - !GetAtt 
              - ALB1LoadBalancer
              - SecurityGroups
      Tags:
        - Key: Name
          Value: !Join
            - '-'
            - - !Ref NamingPrefix
              - Instance
      VpcId:
        Fn::ImportValue: !Sub '${VPCImportName}'

  WebAppAutoScalingGroup:
    #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-group.html
    Type: 'AWS::AutoScaling::AutoScalingGroup'
    Properties:
      # To make it faster to update the server during the lab,
      # we will be replacing the AutoScalingGroup. Therefore
      # we must let CloudFormation name it
      # AutoScalingGroupName: !Sub '${NamingPrefix}'
      VPCZoneIdentifier:
        - Fn::ImportValue: !Sub '${VPCImportName}-App1Subnet1'
        - Fn::ImportValue: !Sub '${VPCImportName}-App1Subnet2'
        - Fn::ImportValue: !Sub '${VPCImportName}-App1Subnet3'
      LaunchConfigurationName: !Ref Web1LaunchConfig
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



static/Reliability/Common/Code/CloudFormation/staticwebapp.yaml [116:252]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Resources:

  DynamoDBServiceMockTable:
    Type: 'AWS::DynamoDB::Table'
    Properties: 
      TableName: 'RecommendationService'
      AttributeDefinitions: 
        - 
          AttributeName: 'ServiceAPI'
          AttributeType: 'S'
        - 
          AttributeName: 'UserID'
          AttributeType: 'N'
      KeySchema: 
        - 
          AttributeName: 'ServiceAPI'
          KeyType: 'HASH'
        - 
          AttributeName: 'UserID'
          KeyType: 'RANGE'
      ProvisionedThroughput: 
        ReadCapacityUnits: '5'
        WriteCapacityUnits: '5'
      SSESpecification: 
        SSEEnabled: 'true'

  ALB1SecurityGroup:
    Type: 'AWS::EC2::SecurityGroup'
    Properties:
      GroupDescription: >-
        Enable HTTP access via port 80 and 443 to the allowed CIDR
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: '80'
          ToPort: '80'
          CidrIp: !Ref ALBSGSource
        - IpProtocol: tcp
          FromPort: '443'
          ToPort: '443'
          CidrIp: !Ref ALBSGSource
      Tags:
        - Key: Name
          Value: !Join
            - '-'
            - - !Ref NamingPrefix
              - Load Balancer
      VpcId:
        Fn::ImportValue: !Sub '${VPCImportName}'

  ALB1LoadBalancer:
    Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
    #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticloadbalancingv2-loadbalancer.html
    Properties:
      SecurityGroups:
        - Ref: ALB1SecurityGroup
      Subnets:
        - Fn::ImportValue: !Sub '${VPCImportName}-${VPCImportALB1Subnet1}'
        - Fn::ImportValue: !Sub '${VPCImportName}-${VPCImportALB1Subnet2}'
        - Fn::ImportValue: !Sub '${VPCImportName}-${VPCImportALB1Subnet3}'

  ALB1Listener:
    Type: 'AWS::ElasticLoadBalancingV2::Listener'
    #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticloadbalancingv2-listener.html
    Properties:
      #  Certificates:
        #- Certificate
      DefaultActions:
        - Type: forward
          TargetGroupArn: !Ref ALB1TargetGroup
      LoadBalancerArn: !Ref ALB1LoadBalancer
      Port: '80'
      Protocol: HTTP

  ALB1TargetGroup:
    Type: 'AWS::ElasticLoadBalancingV2::TargetGroup'
    #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticloadbalancingv2-targetgroup.html
    Properties:
      HealthCheckPath: /healthcheck
      HealthCheckIntervalSeconds: 15
      #HealthCheckPort: 
      #HealthCheckProtocol:
      HealthCheckTimeoutSeconds: 3
      HealthyThresholdCount: 2
      Port: 80
      Protocol: HTTP
      # A short drain time helps speed up the lab
      TargetGroupAttributes:
        - Key: deregistration_delay.timeout_seconds
          Value: 10
      UnhealthyThresholdCount: 3
      VpcId: 
        Fn::ImportValue: !Sub '${VPCImportName}'

  Web1InstanceSecurityGroup:
    Type: 'AWS::EC2::SecurityGroup'
    Properties:
      GroupDescription: >-
        Enable HTTP access via port 80 and 443 restricted to the load balancer
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: '80'
          ToPort: '80'
          SourceSecurityGroupId: !Select 
            - 0
            - !GetAtt 
              - ALB1LoadBalancer
              - SecurityGroups
        - IpProtocol: tcp
          FromPort: '443'
          ToPort: '443'
          SourceSecurityGroupId: !Select 
            - 0
            - !GetAtt 
              - ALB1LoadBalancer
              - SecurityGroups
      Tags:
        - Key: Name
          Value: !Join
            - '-'
            - - !Ref NamingPrefix
              - Instance
      VpcId:
        Fn::ImportValue: !Sub '${VPCImportName}'

  WebAppAutoScalingGroup:
    Type: 'AWS::AutoScaling::AutoScalingGroup'
    #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-group.html
    Properties:
      # To make it faster to update the server during the lab,
      # we will be replacing the AutoScalingGroup. Therefore
      # we must let CloudFormation name it
      # AutoScalingGroupName: !Sub '${NamingPrefix}'
      VPCZoneIdentifier:
        - Fn::ImportValue: !Sub '${VPCImportName}-App1Subnet1'
        - Fn::ImportValue: !Sub '${VPCImportName}-App1Subnet2'
        - Fn::ImportValue: !Sub '${VPCImportName}-App1Subnet3'
      LaunchConfigurationName: !Ref Web1LaunchConfig
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



