{
  "AWSTemplateFormatVersion" : "2010-09-09",

  "Description" : "AWS CloudFormation Sample Template EC2_Instance_With_Ephemeral_Drives: Example to show how to attach ephemeral drives using EC2 block device mappings. **WARNING** This template creates an Amazon EC2 instance. You will be billed for the AWS resources used if you create a stack from this template.",

  "Parameters" : {
    "KeyName": {
      "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the web server",
      "Type": "AWS::EC2::KeyPair::KeyName",
      "ConstraintDescription" : "must be the name of an existing EC2 KeyPair."
    },

    "InstanceType" : {
      "Description" : "WebServer EC2 instance type",
      "Type" : "String",
      "Default" : "t3.small",
      "AllowedValues" : [ "c5.18xlarge", "c5.2xlarge", "c5.4xlarge", "c5.9xlarge", "c5.large", "c5.xlarge", "d2.2xlarge", "d2.4xlarge", "d2.8xlarge", "d2.xlarge", "i3.16xlarge", "i3.2xlarge", "i3.4xlarge", "i3.8xlarge", "i3.large", "i3.xlarge", "m5.12xlarge", "m5.24xlarge", "m5.2xlarge", "m5.4xlarge", "m5.large", "m5.xlarge", "t3.2xlarge", "t3.large", "t3.medium", "t3.micro", "t3.nano", "t3.small", "t3.xlarge" ]
,
      "ConstraintDescription" : "must be a valid EC2 instance type."
    },

    "SSHLocation": {
      "Description": "Lockdown SSH access to the bastion host (default can be accessed from anywhere)",
      "Type": "String",
      "MinLength": "9",
      "MaxLength": "18",
      "Default": "0.0.0.0/0",
      "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})",
      "ConstraintDescription": "must be a valid CIDR range of the form x.x.x.x/x."
    }
  },

  "Mappings" : {
    "AWSInstanceType2Arch" : {
      "c5.18xlarge" : { "Arch" : "HVM64"  },
      "c5.2xlarge" : { "Arch" : "HVM64"  },
      "c5.4xlarge" : { "Arch" : "HVM64"  },
      "c5.9xlarge" : { "Arch" : "HVM64"  },
      "c5.large" : { "Arch" : "HVM64"  },
      "c5.xlarge" : { "Arch" : "HVM64"  },
      "d2.2xlarge" : { "Arch" : "HVM64"  },
      "d2.4xlarge" : { "Arch" : "HVM64"  },
      "d2.8xlarge" : { "Arch" : "HVM64"  },
      "d2.xlarge" : { "Arch" : "HVM64"  },
      "i3.16xlarge" : { "Arch" : "HVM64"  },
      "i3.2xlarge" : { "Arch" : "HVM64"  },
      "i3.4xlarge" : { "Arch" : "HVM64"  },
      "i3.8xlarge" : { "Arch" : "HVM64"  },
      "i3.large" : { "Arch" : "HVM64"  },
      "i3.xlarge" : { "Arch" : "HVM64"  },
      "m5.12xlarge" : { "Arch" : "HVM64"  },
      "m5.24xlarge" : { "Arch" : "HVM64"  },
      "m5.2xlarge" : { "Arch" : "HVM64"  },
      "m5.4xlarge" : { "Arch" : "HVM64"  },
      "m5.large" : { "Arch" : "HVM64"  },
      "m5.xlarge" : { "Arch" : "HVM64"  },
      "t3.2xlarge" : { "Arch" : "HVM64"  },
      "t3.large" : { "Arch" : "HVM64"  },
      "t3.medium" : { "Arch" : "HVM64"  },
      "t3.micro" : { "Arch" : "HVM64"  },
      "t3.nano" : { "Arch" : "HVM64"  },
      "t3.small" : { "Arch" : "HVM64"  },
      "t3.xlarge" : { "Arch" : "HVM64"  }
    },

    "AWSInstanceType2NATArch" : {
      "c5.18xlarge" : { "Arch" : "NATHVM64"  },
      "c5.2xlarge" : { "Arch" : "NATHVM64"  },
      "c5.4xlarge" : { "Arch" : "NATHVM64"  },
      "c5.9xlarge" : { "Arch" : "NATHVM64"  },
      "c5.large" : { "Arch" : "NATHVM64"  },
      "c5.xlarge" : { "Arch" : "NATHVM64"  },
      "d2.2xlarge" : { "Arch" : "NATHVM64"  },
      "d2.4xlarge" : { "Arch" : "NATHVM64"  },
      "d2.8xlarge" : { "Arch" : "NATHVM64"  },
      "d2.xlarge" : { "Arch" : "NATHVM64"  },
      "i3.16xlarge" : { "Arch" : "NATHVM64"  },
      "i3.2xlarge" : { "Arch" : "NATHVM64"  },
      "i3.4xlarge" : { "Arch" : "NATHVM64"  },
      "i3.8xlarge" : { "Arch" : "NATHVM64"  },
      "i3.large" : { "Arch" : "NATHVM64"  },
      "i3.xlarge" : { "Arch" : "NATHVM64"  },
      "m5.12xlarge" : { "Arch" : "NATHVM64"  },
      "m5.24xlarge" : { "Arch" : "NATHVM64"  },
      "m5.2xlarge" : { "Arch" : "NATHVM64"  },
      "m5.4xlarge" : { "Arch" : "NATHVM64"  },
      "m5.large" : { "Arch" : "NATHVM64"  },
      "m5.xlarge" : { "Arch" : "NATHVM64"  },
      "t3.2xlarge" : { "Arch" : "NATHVM64"  },
      "t3.large" : { "Arch" : "NATHVM64"  },
      "t3.medium" : { "Arch" : "NATHVM64"  },
      "t3.micro" : { "Arch" : "NATHVM64"  },
      "t3.nano" : { "Arch" : "NATHVM64"  },
      "t3.small" : { "Arch" : "NATHVM64"  },
      "t3.xlarge" : { "Arch" : "NATHVM64"  }
    }
,
    "AWSRegionArch2AMI" : {
      "us-gov-west-1"    : {"HVM64" : "ami-0d8b6989d85ad62dc", "HVMG2" : "NOT_SUPPORTED"},
      "us-gov-east-1"    : {"HVM64" : "ami-01a0fec9b29fa36fc", "HVMG2" : "NOT_SUPPORTED"}
    }

  },

  "Resources" : {
    "EC2Instance" : {
      "Type" : "AWS::EC2::Instance", 
      "Properties" : {
        "KeyName" : { "Ref" : "KeyName" },
        "InstanceType" : { "Ref" : "InstanceType" },
        "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" },
                          { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] },
        "SecurityGroups" : [{ "Ref" : "EC2SecurityGroup" }],
        "BlockDeviceMappings" : [
          {
            "DeviceName"  : "/dev/sdc",
            "VirtualName" : "ephemeral0"
          }
        ]
      }
    },

    "EC2SecurityGroup" : {
      "Type" : "AWS::EC2::SecurityGroup",
      "Properties" : {
        "GroupDescription" : "SSH access",
        "SecurityGroupIngress" : [{ "IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : { "Ref" : "SSHLocation" }}]
      }
    }
  },

  "Outputs" : {
    "Instance" : {
      "Value" : { "Fn::GetAtt" : [ "EC2Instance", "PublicDnsName" ] }, 
      "Description" : "DNS Name of the newly created EC2 instance"
    }
  }
}
