static/Reliability/200_Backup_Restore_Failback_Analytics/Code/cfn/dr-infra.yaml [164:369]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  IngestFn:
    Type: AWS::Lambda::Function
    Properties:
      Description: Accept incoming messages and relay to a Kinesis stream
      Runtime: python3.7
      Role: !GetAtt IngestFnRole.Arn
      Handler: index.handler
      Environment:
        Variables:
          StreamName: !Ref RawStream
      Timeout: 10
      Tags:
        - Key: Project
          Value: !Ref ProjectName
        - Key: Name
          Value: !Join ["", [!Ref ProjectName, "-IngestFn"]]
      Code:
        ZipFile: |
          import boto3
          import os
          import time
          import json
          import base64

          kinesis = boto3.client('kinesis')
          stream = os.environ['StreamName']
          pkey = str(int(time.time()))

          def handler(event, context):
            print('Received event: ' + str(event))
            record = event['body']
            decodedBytes = base64.b64decode(record)
            decodedStr = str(decodedBytes, "utf-8")

            scode = 200
            sdesc = "200 OK"
            try:
              kinesis.put_record(
                  StreamName=stream,
                  Data=decodedStr + "\n",
                  PartitionKey=pkey)
            except Exception as e:
              print("Failed writing to Kinesis")
              scode = 400
              sdesc = "400 Failed"

            return {
                "isBase64Encoded": False,
                "statusCode": scode,
                "statusDescription": sdesc,
                "body": sdesc
            }

  VPC:
    Type: "AWS::EC2::VPC"
    Properties:
      CidrBlock: !Ref vpccidr
      EnableDnsHostnames: 'true'
      EnableDnsSupport: 'true'
      Tags:
        -
          Key: Project
          Value: !Ref ProjectName
        -
          Key: Name
          Value: !Join ["", [!Ref ProjectName, "-VPC"]]

  IGW:
    Type: "AWS::EC2::InternetGateway"
    Properties:
      Tags:
        -
          Key: Project
          Value: !Ref ProjectName
        -
          Key: Name
          Value: !Join ["", [!Ref ProjectName, "-IGW"]]
  GatewayAttach:
    Type: "AWS::EC2::VPCGatewayAttachment"
    Properties:
      InternetGatewayId: !Ref IGW
      VpcId: !Ref VPC
  
  SubnetPublicA: 
    Type: "AWS::EC2::Subnet"
    Properties:
      AvailabilityZone: !Select [0, !GetAZs ]
      CidrBlock: !Ref AppPublicCIDRA
      MapPublicIpOnLaunch: true
      VpcId: !Ref VPC
  SubnetRouteTableAssociatePublicA: 
    DependsOn: SubnetPublicA
    Type: "AWS::EC2::SubnetRouteTableAssociation"
    Properties:
      RouteTableId: !Ref RouteTablePublic
      SubnetId: !Ref SubnetPublicA
  RouteDefaultPublic:
    Type: "AWS::EC2::Route"
    DependsOn: GatewayAttach
    Properties:
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId: !Ref IGW
      RouteTableId: !Ref RouteTablePublic
  RouteTablePublic:
    Type: "AWS::EC2::RouteTable"
    Properties:
      VpcId: !Ref VPC
  EIPNatGWA:
    DependsOn: GatewayAttach
    Type: "AWS::EC2::EIP"
    Properties:
      Domain: vpc
  NatGatewayA:
    Type: "AWS::EC2::NatGateway"
    Properties:
      AllocationId: !GetAtt EIPNatGWA.AllocationId
      SubnetId: !Ref SubnetPublicA
  RouteTablePrivateA:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref VPC
      Tags:
        -
          Key: Project
          Value: !Ref ProjectName
        -
          Key: Name
          Value: !Join ["", [!Ref ProjectName, "-RT-PrivateA"]]
  PrivateSubnetRouteTableAssociationA:
    DependsOn: SubnetPrivateA
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref SubnetPrivateA
      RouteTableId: !Ref RouteTablePrivateA
  RouteDefaultPrivateA:
    Type: "AWS::EC2::Route"
    Properties:
      DestinationCidrBlock: 0.0.0.0/0
      NatGatewayId: !Ref NatGatewayA
      RouteTableId: !Ref RouteTablePrivateA
  SubnetPrivateA:
    Type: "AWS::EC2::Subnet"
    Properties:
      AvailabilityZone: !Select [0, !GetAZs ]
      CidrBlock: !Ref AppPrivateCIDRA
      MapPublicIpOnLaunch: false
      VpcId: !Ref VPC
      Tags:
        -
          Key: Project
          Value: !Ref ProjectName
        -
          Key: Name
          Value: !Join ["", [!Ref ProjectName, "-Subnet-PrivateA"]]
  SubnetPrivateB:
    Type: "AWS::EC2::Subnet"
    Properties:
      AvailabilityZone: !Select [1, !GetAZs ]
      CidrBlock: !Ref AppPrivateCIDRB
      MapPublicIpOnLaunch: false
      VpcId: !Ref VPC
      Tags:
        -
          Key: Project
          Value: !Ref ProjectName
        -
          Key: Name
          Value: !Join ["", [!Ref ProjectName, "-Subnet-PrivateB"]]
  SubnetPrivateC:
    Type: "AWS::EC2::Subnet"
    Properties:
      AvailabilityZone: !Select [2, !GetAZs ]
      CidrBlock: !Ref AppPrivateCIDRC
      MapPublicIpOnLaunch: false
      VpcId: !Ref VPC
      Tags:
        -
          Key: Project
          Value: !Ref ProjectName
        -
          Key: Name
          Value: !Join ["", [!Ref ProjectName, "-Subnet-PrivateC"]]
  SubnetPrivateD:
    Type: "AWS::EC2::Subnet"
    Properties:
      AvailabilityZone: !Select [0, !GetAZs ]
      CidrBlock: !Ref AppPrivateCIDRD
      MapPublicIpOnLaunch: false
      VpcId: !Ref VPC
      Tags:
        -
          Key: Project
          Value: !Ref ProjectName
        -
          Key: Name
          Value: !Join ["", [!Ref ProjectName, "-Subnet-PrivateD"]]

  LbSecurityGroup:
    Type: "AWS::EC2::SecurityGroup"
    Properties:
      GroupDescription: "ALB Security Group"
      SecurityGroupIngress:
        - SourcePrefixListId: !Ref AllowedPrefixIngress
          IpProtocol: "TCP"
          FromPort: 80
          ToPort: 80
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



static/Reliability/200_Backup_Restore_Failback_Analytics/Code/cfn/workload.yaml [238:443]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  IngestFn:
    Type: AWS::Lambda::Function
    Properties:
      Description: Accept incoming messages and relay to a Kinesis stream
      Runtime: python3.7
      Role: !GetAtt IngestFnRole.Arn
      Handler: index.handler
      Environment:
        Variables:
          StreamName: !Ref RawStream
      Timeout: 10
      Tags:
        - Key: Project
          Value: !Ref ProjectName
        - Key: Name
          Value: !Join ["", [!Ref ProjectName, "-IngestFn"]]
      Code:
        ZipFile: |
          import boto3
          import os
          import time
          import json
          import base64

          kinesis = boto3.client('kinesis')
          stream = os.environ['StreamName']
          pkey = str(int(time.time()))

          def handler(event, context):
            print('Received event: ' + str(event))
            record = event['body']
            decodedBytes = base64.b64decode(record)
            decodedStr = str(decodedBytes, "utf-8")

            scode = 200
            sdesc = "200 OK"
            try:
              kinesis.put_record(
                  StreamName=stream,
                  Data=decodedStr + "\n",
                  PartitionKey=pkey)
            except Exception as e:
              print("Failed writing to Kinesis")
              scode = 400
              sdesc = "400 Failed"

            return {
                "isBase64Encoded": False,
                "statusCode": scode,
                "statusDescription": sdesc,
                "body": sdesc
            }

  VPC:
    Type: "AWS::EC2::VPC"
    Properties:
      CidrBlock: !Ref vpccidr
      EnableDnsHostnames: 'true'
      EnableDnsSupport: 'true'
      Tags:
        -
          Key: Project
          Value: !Ref ProjectName
        -
          Key: Name
          Value: !Join ["", [!Ref ProjectName, "-VPC"]]

  IGW:
    Type: "AWS::EC2::InternetGateway"
    Properties:
      Tags:
        -
          Key: Project
          Value: !Ref ProjectName
        -
          Key: Name
          Value: !Join ["", [!Ref ProjectName, "-IGW"]]
  GatewayAttach:
    Type: "AWS::EC2::VPCGatewayAttachment"
    Properties:
      InternetGatewayId: !Ref IGW
      VpcId: !Ref VPC
  
  SubnetPublicA: 
    Type: "AWS::EC2::Subnet"
    Properties:
      AvailabilityZone: !Select [0, !GetAZs ]
      CidrBlock: !Ref AppPublicCIDRA
      MapPublicIpOnLaunch: true
      VpcId: !Ref VPC
  SubnetRouteTableAssociatePublicA: 
    DependsOn: SubnetPublicA
    Type: "AWS::EC2::SubnetRouteTableAssociation"
    Properties:
      RouteTableId: !Ref RouteTablePublic
      SubnetId: !Ref SubnetPublicA
  RouteDefaultPublic:
    Type: "AWS::EC2::Route"
    DependsOn: GatewayAttach
    Properties:
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId: !Ref IGW
      RouteTableId: !Ref RouteTablePublic
  RouteTablePublic:
    Type: "AWS::EC2::RouteTable"
    Properties:
      VpcId: !Ref VPC
  EIPNatGWA:
    DependsOn: GatewayAttach
    Type: "AWS::EC2::EIP"
    Properties:
      Domain: vpc
  NatGatewayA:
    Type: "AWS::EC2::NatGateway"
    Properties:
      AllocationId: !GetAtt EIPNatGWA.AllocationId
      SubnetId: !Ref SubnetPublicA
  RouteTablePrivateA:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref VPC
      Tags:
        -
          Key: Project
          Value: !Ref ProjectName
        -
          Key: Name
          Value: !Join ["", [!Ref ProjectName, "-RT-PrivateA"]]
  PrivateSubnetRouteTableAssociationA:
    DependsOn: SubnetPrivateA
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref SubnetPrivateA
      RouteTableId: !Ref RouteTablePrivateA
  RouteDefaultPrivateA:
    Type: "AWS::EC2::Route"
    Properties:
      DestinationCidrBlock: 0.0.0.0/0
      NatGatewayId: !Ref NatGatewayA
      RouteTableId: !Ref RouteTablePrivateA
  SubnetPrivateA:
    Type: "AWS::EC2::Subnet"
    Properties:
      AvailabilityZone: !Select [0, !GetAZs ]
      CidrBlock: !Ref AppPrivateCIDRA
      MapPublicIpOnLaunch: false
      VpcId: !Ref VPC
      Tags:
        -
          Key: Project
          Value: !Ref ProjectName
        -
          Key: Name
          Value: !Join ["", [!Ref ProjectName, "-Subnet-PrivateA"]]
  SubnetPrivateB:
    Type: "AWS::EC2::Subnet"
    Properties:
      AvailabilityZone: !Select [1, !GetAZs ]
      CidrBlock: !Ref AppPrivateCIDRB
      MapPublicIpOnLaunch: false
      VpcId: !Ref VPC
      Tags:
        -
          Key: Project
          Value: !Ref ProjectName
        -
          Key: Name
          Value: !Join ["", [!Ref ProjectName, "-Subnet-PrivateB"]]
  SubnetPrivateC:
    Type: "AWS::EC2::Subnet"
    Properties:
      AvailabilityZone: !Select [2, !GetAZs ]
      CidrBlock: !Ref AppPrivateCIDRC
      MapPublicIpOnLaunch: false
      VpcId: !Ref VPC
      Tags:
        -
          Key: Project
          Value: !Ref ProjectName
        -
          Key: Name
          Value: !Join ["", [!Ref ProjectName, "-Subnet-PrivateC"]]
  SubnetPrivateD:
    Type: "AWS::EC2::Subnet"
    Properties:
      AvailabilityZone: !Select [0, !GetAZs ]
      CidrBlock: !Ref AppPrivateCIDRD
      MapPublicIpOnLaunch: false
      VpcId: !Ref VPC
      Tags:
        -
          Key: Project
          Value: !Ref ProjectName
        -
          Key: Name
          Value: !Join ["", [!Ref ProjectName, "-Subnet-PrivateD"]]

  LbSecurityGroup:
    Type: "AWS::EC2::SecurityGroup"
    Properties:
      GroupDescription: "ALB Security Group"
      SecurityGroupIngress:
        - SourcePrefixListId: !Ref AllowedPrefixIngress
          IpProtocol: "TCP"
          FromPort: 80
          ToPort: 80
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



