|
| 1 | +{ |
| 2 | + "AWSTemplateFormatVersion" : "2010-09-09", |
| 3 | + |
| 4 | + "Description" : "This Template launch EC2 Instance Linux and Install Apache Web Server Start the Service. **WARNING** This Template will launch t2.micro instance, if your eligible for Free Tier no charges will be applied, other than Free tier users will get cost from amazon.", |
| 5 | + |
| 6 | + "Parameters" : { |
| 7 | + |
| 8 | + "KeyName": { |
| 9 | + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", |
| 10 | + "Type": "AWS::EC2::KeyPair::KeyName", |
| 11 | + "ConstraintDescription" : "must be the name of an existing EC2 KeyPair." |
| 12 | + }, |
| 13 | + |
| 14 | + "InstanceType" : { |
| 15 | + "Description" : "WebServer EC2 instance type", |
| 16 | + "Type" : "String", |
| 17 | + "Default" : "t2.micro", |
| 18 | + "AllowedValues" : [ "t2.micro" ], |
| 19 | + "ConstraintDescription" : "must be a valid EC2 instance type." |
| 20 | + }, |
| 21 | + |
| 22 | + "SSHLocation": { |
| 23 | + "Description": "The IP address range that can be used to SSH to the EC2 instances", |
| 24 | + "Type": "String", |
| 25 | + "MinLength": "9", |
| 26 | + "MaxLength": "18", |
| 27 | + "Default": "0.0.0.0/0", |
| 28 | + "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})", |
| 29 | + "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x." |
| 30 | + } |
| 31 | + }, |
| 32 | + |
| 33 | + "Mappings" : { |
| 34 | + "AWSInstanceType2Arch" : { |
| 35 | + "t2.micro" : { "Arch" : "HVM64" } |
| 36 | + }, |
| 37 | + |
| 38 | + "AWSRegionArch2AMI" : { |
| 39 | + "us-east-1" : {"HVM64" : "ami-0ff8a91507f77f867", "HVMG2" : "ami-0a584ac55a7631c0c"}, |
| 40 | + "us-west-2" : {"HVM64" : "ami-a0cfeed8", "HVMG2" : "ami-0e09505bc235aa82d"}, |
| 41 | + "us-west-1" : {"HVM64" : "ami-0bdb828fd58c52235", "HVMG2" : "ami-066ee5fd4a9ef77f1"}, |
| 42 | + "eu-west-1" : {"HVM64" : "ami-047bb4163c506cd98", "HVMG2" : "ami-0a7c483d527806435"}, |
| 43 | + "eu-west-2" : {"HVM64" : "ami-f976839e", "HVMG2" : "NOT_SUPPORTED"}, |
| 44 | + "eu-west-3" : {"HVM64" : "ami-0ebc281c20e89ba4b", "HVMG2" : "NOT_SUPPORTED"}, |
| 45 | + "eu-central-1" : {"HVM64" : "ami-0233214e13e500f77", "HVMG2" : "ami-06223d46a6d0661c7"}, |
| 46 | + "ap-northeast-1" : {"HVM64" : "ami-06cd52961ce9f0d85", "HVMG2" : "ami-053cdd503598e4a9d"}, |
| 47 | + "ap-northeast-2" : {"HVM64" : "ami-0a10b2721688ce9d2", "HVMG2" : "NOT_SUPPORTED"}, |
| 48 | + "ap-northeast-3" : {"HVM64" : "ami-0d98120a9fb693f07", "HVMG2" : "NOT_SUPPORTED"}, |
| 49 | + "ap-southeast-1" : {"HVM64" : "ami-08569b978cc4dfa10", "HVMG2" : "ami-0be9df32ae9f92309"}, |
| 50 | + "ap-southeast-2" : {"HVM64" : "ami-09b42976632b27e9b", "HVMG2" : "ami-0a9ce9fecc3d1daf8"}, |
| 51 | + "ap-south-1" : {"HVM64" : "ami-0912f71e06545ad88", "HVMG2" : "ami-097b15e89dbdcfcf4"}, |
| 52 | + "us-east-2" : {"HVM64" : "ami-0b59bfac6be064b78", "HVMG2" : "NOT_SUPPORTED"}, |
| 53 | + "ca-central-1" : {"HVM64" : "ami-0b18956f", "HVMG2" : "NOT_SUPPORTED"}, |
| 54 | + "sa-east-1" : {"HVM64" : "ami-07b14488da8ea02a0", "HVMG2" : "NOT_SUPPORTED"}, |
| 55 | + "cn-north-1" : {"HVM64" : "ami-0a4eaf6c4454eda75", "HVMG2" : "NOT_SUPPORTED"}, |
| 56 | + "cn-northwest-1" : {"HVM64" : "ami-6b6a7d09", "HVMG2" : "NOT_SUPPORTED"} |
| 57 | + } |
| 58 | + |
| 59 | + |
| 60 | + }, |
| 61 | + |
| 62 | + "Resources" : { |
| 63 | + "WebServerSecurityGroup" : { |
| 64 | + "Type" : "AWS::EC2::SecurityGroup", |
| 65 | + "Properties" : { |
| 66 | + "GroupDescription" : "Enable HTTP access via port 80 locked down to the load balancer + SSH access", |
| 67 | + "SecurityGroupIngress" : [ |
| 68 | + {"IpProtocol" : "tcp", "FromPort" : "80", "ToPort" : "80", "CidrIp" : "0.0.0.0/0"}, |
| 69 | + {"IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : { "Ref" : "SSHLocation"}} |
| 70 | + ] |
| 71 | + } |
| 72 | + }, |
| 73 | + |
| 74 | + "WebServer": { |
| 75 | + "Type" : "AWS::EC2::Instance", |
| 76 | + "Properties": { |
| 77 | + "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, |
| 78 | + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, |
| 79 | + "InstanceType" : { "Ref" : "InstanceType" }, |
| 80 | + "SecurityGroups" : [ {"Ref" : "WebServerSecurityGroup"} ], |
| 81 | + "KeyName" : { "Ref" : "KeyName" }, |
| 82 | + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ |
| 83 | + "#!/bin/bash\n", |
| 84 | + "sudo yum update -y\n", |
| 85 | + "sudo yum install httpd -y\n", |
| 86 | + "sudo service start httpd\n", |
| 87 | + "sudo echo '<html><h1>Welcome To Web Server</h1></html>' > /var/www/html/index.html\n", |
| 88 | + "sudo chkconfig httpd on\n" |
| 89 | + ]]}} |
| 90 | + } |
| 91 | + } |
| 92 | + }, |
| 93 | + |
| 94 | + "Outputs" : { |
| 95 | + "WebsiteURL" : { |
| 96 | + "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WebServer", "PublicDnsName" ]} ]]}, |
| 97 | + "Description" : "WordPress Website" |
| 98 | + } |
| 99 | + } |
| 100 | +} |
0 commit comments