static/Reliability/200_Deploy_and_Update_CloudFormation/Code/CloudFormation/simple_stack_plus_s3.yaml [126:297]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  SimpleVPC:
    Type: AWS::EC2::VPC
    Properties:
      #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpc.html
      CidrBlock: !Ref VPCCidrBlock
      EnableDnsSupport: true
      EnableDnsHostnames: true
      Tags:
        - Key: Name
          Value: !Join
            - '-'
            - - !Ref NamingPrefix
              - VPC

  #Internet Gateway: Allows communication between instances in your VPC and the internet.
  IGW:
    Condition: PublicEnabled
    #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-internetgateway.html
    Type: AWS::EC2::InternetGateway
    Properties:
      Tags:
        - Key: Name
          Value: !Join
            - '-'
            - - !Ref NamingPrefix
              - IGW
  IGWAttach:
    Condition: PublicEnabled
    #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpc-gateway-attachment.html
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      VpcId: !Ref SimpleVPC
      InternetGatewayId: !Ref IGW
      #VpnGatewayId


  ###########
  # Route Table to Internet
  ###########

  # Route to/from Internet
  InternetRoute:
    Condition: PublicEnabled
    Type: AWS::EC2::Route
    #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-route.html
    Properties:
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId: !Ref IGW
      RouteTableId: !Ref InternetRouteTable

  InternetRouteTable:
    Condition: PublicEnabled
    #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-route-table.html
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref SimpleVPC
      Tags:
        - Key: Name
          Value: !Join
            - '-'
            - - !Ref NamingPrefix
              - Public
              - RTB

  ###########
  # Public Subnet
  ###########

  PublicSubnet1:
    Condition: PublicEnabled
    Type: AWS::EC2::Subnet
    #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-subnet.html
    Properties:
      VpcId: !Ref SimpleVPC
      AvailabilityZone: !Select
        - 0
        - !GetAZs #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getavailabilityzones.html
          Ref: 'AWS::Region'
      CidrBlock: !Ref PublicCidrBlock1
      MapPublicIpOnLaunch: false
      Tags:
        - Key: Name
          Value: !Join
            - '-'
            - - !Ref NamingPrefix
              - Public
              - 1

  PublicSubnet1RouteToInternet:
    Condition: PublicEnabled
    Type: AWS::EC2::SubnetRouteTableAssociation
    #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-subnet-route-table-assoc.html
    DependsOn:
      - PublicSubnet1
      - InternetRouteTable
    Properties:
      RouteTableId: !Ref InternetRouteTable
      SubnetId: !Ref PublicSubnet1

###########
# App Security Group
###########

  PublicSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Condition: EC2SecurityEnabled
    Properties:
      VpcId: !Ref SimpleVPC
      GroupName: !Join
        - '-'
        - - !Ref NamingPrefix
          - SG
      GroupDescription: >-
        Enable HTTP access via port 80 and 443 to the allowed CIDR
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: '80'
          ToPort: '80'
          CidrIp: !Ref PublicSGSource
        - IpProtocol: tcp
          FromPort: '443'
          ToPort: '443'
          CidrIp: !Ref PublicSGSource
      Tags:
        - Key: Name
          Value: !Join
            - '-'
            - - !Ref NamingPrefix
              - SG

########################################################################

Outputs:

  SimpleVPCId:
    Value: !Ref SimpleVPC

########################################################################
# Metadata is used to group and order how the CloudFormation parameters are
# displayed when you deploy the template using the AWS Console
Metadata:
  AWS::CloudFormation::Interface:
    ParameterGroups:
      -
        Label:
          default: "Naming"
        Parameters:
          - NamingPrefix
      -
        Label:
          default: "true/false switches"
        Parameters:
          - PublicEnabledParam
          - EC2SecurityEnabledParam
      -
        Label:
          default: "S3 bucket"
        Parameters:
          - S3BucketName
      -
        Label:
          default: "IP configuration (CIDR)"
        Parameters:
          - VPCCidrBlock
          - PublicCidrBlock1
          - PublicSGSource
      -
        Label:
          default: "EC2 configuration"
        Parameters:
          - LatestAmiId
          - InstanceType
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



static/Reliability/200_Deploy_and_Update_CloudFormation/Code/CloudFormation/simple_stack_plus_s3_ec2.yaml [139:310]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  SimpleVPC:
    Type: AWS::EC2::VPC
    Properties:
      #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpc.html
      CidrBlock: !Ref VPCCidrBlock
      EnableDnsSupport: true
      EnableDnsHostnames: true
      Tags:
        - Key: Name
          Value: !Join
            - '-'
            - - !Ref NamingPrefix
              - VPC

  #Internet Gateway: Allows communication between instances in your VPC and the internet.
  IGW:
    Condition: PublicEnabled
    #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-internetgateway.html
    Type: AWS::EC2::InternetGateway
    Properties:
      Tags:
        - Key: Name
          Value: !Join
            - '-'
            - - !Ref NamingPrefix
              - IGW
  IGWAttach:
    Condition: PublicEnabled
    #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpc-gateway-attachment.html
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      VpcId: !Ref SimpleVPC
      InternetGatewayId: !Ref IGW
      #VpnGatewayId


  ###########
  # Route Table to Internet
  ###########

  # Route to/from Internet
  InternetRoute:
    Condition: PublicEnabled
    Type: AWS::EC2::Route
    #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-route.html
    Properties:
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId: !Ref IGW
      RouteTableId: !Ref InternetRouteTable

  InternetRouteTable:
    Condition: PublicEnabled
    #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-route-table.html
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref SimpleVPC
      Tags:
        - Key: Name
          Value: !Join
            - '-'
            - - !Ref NamingPrefix
              - Public
              - RTB

  ###########
  # Public Subnet
  ###########

  PublicSubnet1:
    Condition: PublicEnabled
    Type: AWS::EC2::Subnet
    #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-subnet.html
    Properties:
      VpcId: !Ref SimpleVPC
      AvailabilityZone: !Select
        - 0
        - !GetAZs #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getavailabilityzones.html
          Ref: 'AWS::Region'
      CidrBlock: !Ref PublicCidrBlock1
      MapPublicIpOnLaunch: false
      Tags:
        - Key: Name
          Value: !Join
            - '-'
            - - !Ref NamingPrefix
              - Public
              - 1

  PublicSubnet1RouteToInternet:
    Condition: PublicEnabled
    Type: AWS::EC2::SubnetRouteTableAssociation
    #https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-subnet-route-table-assoc.html
    DependsOn:
      - PublicSubnet1
      - InternetRouteTable
    Properties:
      RouteTableId: !Ref InternetRouteTable
      SubnetId: !Ref PublicSubnet1

###########
# App Security Group
###########

  PublicSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Condition: EC2SecurityEnabled
    Properties:
      VpcId: !Ref SimpleVPC
      GroupName: !Join
        - '-'
        - - !Ref NamingPrefix
          - SG
      GroupDescription: >-
        Enable HTTP access via port 80 and 443 to the allowed CIDR
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: '80'
          ToPort: '80'
          CidrIp: !Ref PublicSGSource
        - IpProtocol: tcp
          FromPort: '443'
          ToPort: '443'
          CidrIp: !Ref PublicSGSource
      Tags:
        - Key: Name
          Value: !Join
            - '-'
            - - !Ref NamingPrefix
              - SG

########################################################################

Outputs:

  SimpleVPCId:
    Value: !Ref SimpleVPC

########################################################################
# Metadata is used to group and order how the CloudFormation parameters are
# displayed when you deploy the template using the AWS Console
Metadata:
  AWS::CloudFormation::Interface:
    ParameterGroups:
      -
        Label:
          default: "Naming"
        Parameters:
          - NamingPrefix
      -
        Label:
          default: "true/false switches"
        Parameters:
          - PublicEnabledParam
          - EC2SecurityEnabledParam
      -
        Label:
          default: "S3 bucket"
        Parameters:
          - S3BucketName
      -
        Label:
          default: "IP configuration (CIDR)"
        Parameters:
          - VPCCidrBlock
          - PublicCidrBlock1
          - PublicSGSource
      -
        Label:
          default: "EC2 configuration"
        Parameters:
          - LatestAmiId
          - InstanceType
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



