viper25

CloudFormer Template (with SSH Key)

Oct 12th, 2017
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 30.82 KB | None | 0 0
  1. {
  2.   "AWSTemplateFormatVersion" : "2010-09-09",
  3.  
  4.   "Description" : "AWS CloudFormer Beta - template creation prototype application. This tool allows you to create an AWS CloudFormation template from the AWS resources in your AWS account. **Warning** This template creates a single EC2 instance in your account to run the application - you will be billed for the instance at normal AWS EC2 rates.",
  5.  
  6.   "Parameters" : {
  7.  
  8.     "Username" : {
  9.       "Description" : "Username to log in to CloudFormer",
  10.       "Type" : "String"
  11.     },
  12.     "Password" : {
  13.       "Description" : "Password to log in to CloudFormer",
  14.       "Type" : "String",
  15.       "NoEcho" : "true"
  16.     },
  17.     "VPCSelection": {
  18.       "Description": "This setting will control if the Cloudformer Web server will launch in the default VPC or if a new VPC will be created, or if you wish to launch into an existing non-default VPC.",
  19.       "Type": "String",
  20.       "Default": "CreateNewVPC",
  21.       "AllowedValues": [
  22.         "Default",
  23.         "CreateNewVPC"
  24.       ],
  25.       "ConstraintDescription": "must be either Default or CreateNewVPC"
  26.     },
  27.     "KeyName": {
  28.       "Type": "String",
  29.       "Description": "Keyname for the keypair that Qwiklab will use to launch EC2 instances",
  30.       "Default": "My Key Pair"
  31.     }
  32.   },
  33.   "Conditions": {
  34.     "DefaultVPC": {
  35.       "Fn::Equals": [
  36.         {
  37.           "Ref": "VPCSelection"
  38.         },
  39.         "Default"
  40.       ]
  41.     },
  42.     "CreateNewVPC": {
  43.       "Fn::Equals": [
  44.         {
  45.           "Ref": "VPCSelection"
  46.         },
  47.         "CreateNewVPC"
  48.       ]
  49.     }
  50.   },
  51.  
  52.   "Mappings" : {
  53.     "Region2Examples" : {
  54.       "us-east-1"      : { "Examples" : "https://s3.amazonaws.com/cloudformation-examples-us-east-1" },
  55.       "us-west-2"      : { "Examples" : "https://s3-us-west-2.amazonaws.com/cloudformation-examples-us-west-2" },
  56.       "us-west-1"      : { "Examples" : "https://s3-us-west-1.amazonaws.com/cloudformation-examples-us-west-1" },
  57.       "eu-west-1"      : { "Examples" : "https://s3-eu-west-1.amazonaws.com/cloudformation-examples-eu-west-1" },
  58.       "eu-central-1"   : { "Examples" : "https://s3-eu-central-1.amazonaws.com/cloudformation-examples-eu-central-1" },
  59.       "ap-southeast-1" : { "Examples" : "https://s3-ap-southeast-1.amazonaws.com/cloudformation-examples-ap-southeast-1" },
  60.       "ap-northeast-1" : { "Examples" : "https://s3-ap-northeast-1.amazonaws.com/cloudformation-examples-ap-northeast-1" },
  61.       "ap-southeast-2" : { "Examples" : "https://s3-ap-southeast-2.amazonaws.com/cloudformation-examples-ap-southeast-2" },
  62.       "ap-northeast-2" : { "Examples" : "https://s3-ap-northeast-2.amazonaws.com/cloudformation-examples-ap-northeast-2" },
  63.       "ap-south-1"     : { "Examples" : "https://s3-ap-south-1.amazonaws.com/cloudformation-examples-ap-south-1" },
  64.       "us-east-2"      : { "Examples" : "https://s3-us-east-2.amazonaws.com/cloudformation-examples-us-east-2" },
  65.       "sa-east-1"      : { "Examples" : "https://s3-sa-east-1.amazonaws.com/cloudformation-examples-sa-east-1" },
  66.       "cn-north-1"     : { "Examples" : "https://s3.cn-north-1.amazonaws.com.cn/cloudformation-examples-cn-north-1" },
  67.       "ca-central-1"   : { "Examples" : "https://s3-ca-central-1.amazonaws.com/cloudformation-examples-ca-central-1" },
  68.       "eu-west-2"      : { "Examples" : "https://s3-eu-west-2.amazonaws.com/cloudformation-examples-eu-west-2" }
  69.     }
  70. ,
  71.     "Region2Principal" : {
  72.       "us-east-1"      : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
  73.       "us-west-2"      : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
  74.       "us-west-1"      : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
  75.       "eu-west-1"      : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
  76.       "ap-southeast-1" : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
  77.       "ap-northeast-1" : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
  78.       "ap-southeast-2" : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
  79.       "ap-northeast-2" : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
  80.       "ap-south-1"     : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
  81.       "us-east-2"      : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
  82.       "sa-east-1"      : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
  83.       "cn-north-1"     : { "EC2Principal" : "ec2.amazonaws.com.cn", "OpsWorksPrincipal" : "opsworks.amazonaws.com.cn" },
  84.       "eu-central-1"   : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
  85.       "eu-west-2"   : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" },
  86.       "ca-central-1"   : { "EC2Principal" : "ec2.amazonaws.com", "OpsWorksPrincipal" : "opsworks.amazonaws.com" }
  87.     }
  88. ,
  89.     "AWSInstanceType2Arch" : {
  90.       "t1.micro"    : { "Arch" : "PV64"   },
  91.       "t2.nano"     : { "Arch" : "HVM64"  },
  92.       "t2.micro"    : { "Arch" : "HVM64"  },
  93.       "t2.small"    : { "Arch" : "HVM64"  },
  94.       "t2.medium"   : { "Arch" : "HVM64"  },
  95.       "t2.large"    : { "Arch" : "HVM64"  },
  96.       "m1.small"    : { "Arch" : "PV64"   },
  97.       "m1.medium"   : { "Arch" : "PV64"   },
  98.       "m1.large"    : { "Arch" : "PV64"   },
  99.       "m1.xlarge"   : { "Arch" : "PV64"   },
  100.       "m2.xlarge"   : { "Arch" : "PV64"   },
  101.       "m2.2xlarge"  : { "Arch" : "PV64"   },
  102.       "m2.4xlarge"  : { "Arch" : "PV64"   },
  103.       "m3.medium"   : { "Arch" : "HVM64"  },
  104.       "m3.large"    : { "Arch" : "HVM64"  },
  105.       "m3.xlarge"   : { "Arch" : "HVM64"  },
  106.       "m3.2xlarge"  : { "Arch" : "HVM64"  },
  107.       "m4.large"    : { "Arch" : "HVM64"  },
  108.       "m4.xlarge"   : { "Arch" : "HVM64"  },
  109.       "m4.2xlarge"  : { "Arch" : "HVM64"  },
  110.       "m4.4xlarge"  : { "Arch" : "HVM64"  },
  111.       "m4.10xlarge" : { "Arch" : "HVM64"  },
  112.       "c1.medium"   : { "Arch" : "PV64"   },
  113.       "c1.xlarge"   : { "Arch" : "PV64"   },
  114.       "c3.large"    : { "Arch" : "HVM64"  },
  115.       "c3.xlarge"   : { "Arch" : "HVM64"  },
  116.       "c3.2xlarge"  : { "Arch" : "HVM64"  },
  117.       "c3.4xlarge"  : { "Arch" : "HVM64"  },
  118.       "c3.8xlarge"  : { "Arch" : "HVM64"  },
  119.       "c4.large"    : { "Arch" : "HVM64"  },
  120.       "c4.xlarge"   : { "Arch" : "HVM64"  },
  121.       "c4.2xlarge"  : { "Arch" : "HVM64"  },
  122.       "c4.4xlarge"  : { "Arch" : "HVM64"  },
  123.       "c4.8xlarge"  : { "Arch" : "HVM64"  },
  124.       "g2.2xlarge"  : { "Arch" : "HVMG2"  },
  125.       "g2.8xlarge"  : { "Arch" : "HVMG2"  },
  126.       "r3.large"    : { "Arch" : "HVM64"  },
  127.       "r3.xlarge"   : { "Arch" : "HVM64"  },
  128.       "r3.2xlarge"  : { "Arch" : "HVM64"  },
  129.       "r3.4xlarge"  : { "Arch" : "HVM64"  },
  130.       "r3.8xlarge"  : { "Arch" : "HVM64"  },
  131.       "i2.xlarge"   : { "Arch" : "HVM64"  },
  132.       "i2.2xlarge"  : { "Arch" : "HVM64"  },
  133.       "i2.4xlarge"  : { "Arch" : "HVM64"  },
  134.       "i2.8xlarge"  : { "Arch" : "HVM64"  },
  135.       "d2.xlarge"   : { "Arch" : "HVM64"  },
  136.       "d2.2xlarge"  : { "Arch" : "HVM64"  },
  137.       "d2.4xlarge"  : { "Arch" : "HVM64"  },
  138.       "d2.8xlarge"  : { "Arch" : "HVM64"  },
  139.       "hi1.4xlarge" : { "Arch" : "HVM64"  },
  140.       "hs1.8xlarge" : { "Arch" : "HVM64"  },
  141.       "cr1.8xlarge" : { "Arch" : "HVM64"  },
  142.       "cc2.8xlarge" : { "Arch" : "HVM64"  }
  143.     },
  144.  
  145.     "AWSInstanceType2NATArch" : {
  146.       "t1.micro"    : { "Arch" : "NATPV64"   },
  147.       "t2.nano"     : { "Arch" : "NATHVM64"  },
  148.       "t2.micro"    : { "Arch" : "NATHVM64"  },
  149.       "t2.small"    : { "Arch" : "NATHVM64"  },
  150.       "t2.medium"   : { "Arch" : "NATHVM64"  },
  151.       "t2.large"    : { "Arch" : "NATHVM64"  },
  152.       "m1.small"    : { "Arch" : "NATPV64"   },
  153.       "m1.medium"   : { "Arch" : "NATPV64"   },
  154.       "m1.large"    : { "Arch" : "NATPV64"   },
  155.       "m1.xlarge"   : { "Arch" : "NATPV64"   },
  156.       "m2.xlarge"   : { "Arch" : "NATPV64"   },
  157.       "m2.2xlarge"  : { "Arch" : "NATPV64"   },
  158.       "m2.4xlarge"  : { "Arch" : "NATPV64"   },
  159.       "m3.medium"   : { "Arch" : "NATHVM64"  },
  160.       "m3.large"    : { "Arch" : "NATHVM64"  },
  161.       "m3.xlarge"   : { "Arch" : "NATHVM64"  },
  162.       "m3.2xlarge"  : { "Arch" : "NATHVM64"  },
  163.       "m4.large"    : { "Arch" : "NATHVM64"  },
  164.       "m4.xlarge"   : { "Arch" : "NATHVM64"  },
  165.       "m4.2xlarge"  : { "Arch" : "NATHVM64"  },
  166.       "m4.4xlarge"  : { "Arch" : "NATHVM64"  },
  167.       "m4.10xlarge" : { "Arch" : "NATHVM64"  },
  168.       "c1.medium"   : { "Arch" : "NATPV64"   },
  169.       "c1.xlarge"   : { "Arch" : "NATPV64"   },
  170.       "c3.large"    : { "Arch" : "NATHVM64"  },
  171.       "c3.xlarge"   : { "Arch" : "NATHVM64"  },
  172.       "c3.2xlarge"  : { "Arch" : "NATHVM64"  },
  173.       "c3.4xlarge"  : { "Arch" : "NATHVM64"  },
  174.       "c3.8xlarge"  : { "Arch" : "NATHVM64"  },
  175.       "c4.large"    : { "Arch" : "NATHVM64"  },
  176.       "c4.xlarge"   : { "Arch" : "NATHVM64"  },
  177.       "c4.2xlarge"  : { "Arch" : "NATHVM64"  },
  178.       "c4.4xlarge"  : { "Arch" : "NATHVM64"  },
  179.       "c4.8xlarge"  : { "Arch" : "NATHVM64"  },
  180.       "g2.2xlarge"  : { "Arch" : "NATHVMG2"  },
  181.       "g2.8xlarge"  : { "Arch" : "NATHVMG2"  },
  182.       "r3.large"    : { "Arch" : "NATHVM64"  },
  183.       "r3.xlarge"   : { "Arch" : "NATHVM64"  },
  184.       "r3.2xlarge"  : { "Arch" : "NATHVM64"  },
  185.       "r3.4xlarge"  : { "Arch" : "NATHVM64"  },
  186.       "r3.8xlarge"  : { "Arch" : "NATHVM64"  },
  187.       "i2.xlarge"   : { "Arch" : "NATHVM64"  },
  188.       "i2.2xlarge"  : { "Arch" : "NATHVM64"  },
  189.       "i2.4xlarge"  : { "Arch" : "NATHVM64"  },
  190.       "i2.8xlarge"  : { "Arch" : "NATHVM64"  },
  191.       "d2.xlarge"   : { "Arch" : "NATHVM64"  },
  192.       "d2.2xlarge"  : { "Arch" : "NATHVM64"  },
  193.       "d2.4xlarge"  : { "Arch" : "NATHVM64"  },
  194.       "d2.8xlarge"  : { "Arch" : "NATHVM64"  },
  195.       "hi1.4xlarge" : { "Arch" : "NATHVM64"  },
  196.       "hs1.8xlarge" : { "Arch" : "NATHVM64"  },
  197.       "cr1.8xlarge" : { "Arch" : "NATHVM64"  },
  198.       "cc2.8xlarge" : { "Arch" : "NATHVM64"  }
  199.     }
  200. ,
  201.     "AWSRegionArch2AMI" : {
  202.       "us-east-1"        : {"PV64" : "ami-2a69aa47", "HVM64" : "ami-7f6aa912", "HVMG2" : "ami-c5eadcd3"},
  203.       "us-west-2"        : {"PV64" : "ami-7f77b31f", "HVM64" : "ami-f469ad94", "HVMG2" : "ami-aaebfcd3"},
  204.       "us-west-1"        : {"PV64" : "ami-a2490dc2", "HVM64" : "ami-594b0f39", "HVMG2" : "ami-68002c08"},
  205.       "eu-west-1"        : {"PV64" : "ami-4cdd453f", "HVM64" : "ami-c5da42b6", "HVMG2" : "ami-ed947194"},
  206.       "eu-west-2"        : {"PV64" : "NOT_SUPPORTED", "HVM64" : "ami-896369ed", "HVMG2" : "NOT_SUPPORTED"},
  207.       "eu-central-1"     : {"PV64" : "ami-6527cf0a", "HVM64" : "ami-e526ce8a", "HVMG2" : "ami-cf3294a0"},
  208.       "ap-northeast-1"   : {"PV64" : "ami-3e42b65f", "HVM64" : "ami-7f4db91e", "HVMG2" : "ami-4e0e1f29"},
  209.       "ap-northeast-2"   : {"PV64" : "NOT_SUPPORTED", "HVM64" : "ami-39448f57", "HVMG2" : "NOT_SUPPORTED"},
  210.       "ap-southeast-1"   : {"PV64" : "ami-df9e4cbc", "HVM64" : "ami-a69b49c5", "HVMG2" : "ami-f35cd290"},
  211.       "ap-southeast-2"   : {"PV64" : "ami-63351d00", "HVM64" : "ami-10361e73", "HVMG2" : "ami-e77c6f84"},
  212.       "ap-south-1"       : {"PV64" : "NOT_SUPPORTED", "HVM64" : "ami-fdbed492", "HVMG2" : "ami-5b6e1034"},
  213.       "us-east-2"        : {"PV64" : "NOT_SUPPORTED", "HVM64" : "ami-d90c57bc", "HVMG2" : "NOT_SUPPORTED"},
  214.       "ca-central-1"     : {"PV64" : "NOT_SUPPORTED", "HVM64" : "ami-33f34157", "HVMG2" : "NOT_SUPPORTED"},
  215.       "sa-east-1"        : {"PV64" : "ami-1ad34676", "HVM64" : "ami-aed144c2", "HVMG2" : "NOT_SUPPORTED"},
  216.       "cn-north-1"       : {"PV64" : "ami-77559f1a", "HVM64" : "ami-14519b79", "HVMG2" : "NOT_SUPPORTED"}
  217.     }
  218.  
  219.   },
  220.  
  221.   "Resources" : {
  222.  
  223.     "CFNRole": {
  224.       "Type": "AWS::IAM::Role",
  225.       "Properties": {
  226.         "AssumeRolePolicyDocument": {
  227.           "Statement": [{
  228.             "Effect": "Allow",
  229.             "Principal": { "Service": { "Fn::FindInMap" : [ "Region2Principal", {"Ref" : "AWS::Region"}, "EC2Principal"]}},
  230.             "Action": [ "sts:AssumeRole" ]
  231.           }]
  232.         },
  233.         "Path": "/"
  234.       }
  235.     },
  236.  
  237.     "CFNRolePolicy": {
  238.       "Type": "AWS::IAM::Policy",
  239.       "Properties": {
  240.         "PolicyName": "CloudFormerPolicy",
  241.         "PolicyDocument": {
  242.           "Statement": [ {
  243.             "Effect": "Allow",
  244.             "Action"   : [
  245.               "autoscaling:Describe*",
  246.               "cloudformation:Describe*",
  247.               "cloudformation:List*",
  248.               "cloudfront:List*",
  249.               "cloudFront:Get*",
  250.               "cloudtrail:Describe*",
  251.               "cloudtrail:Get*",
  252.               "cloudwatch:Describe*",
  253.               "dynamodb:List*",
  254.               "dynamodb:Describe*",
  255.               "elasticbeanstalk:Describe*",
  256.               "ec2:Describe*",
  257.               "elasticloadbalancing:Describe*",
  258.               "elasticache:Describe*",
  259.               "rds:Describe*",
  260.               "rds:List*",
  261.               "route53:List*",
  262.               "route53:Get*",
  263.               "s3:List*",
  264.               "s3:Get*",
  265.               "s3:PutObject",
  266.               "sdb:Get*",
  267.               "sdb:List*",
  268.               "sns:Get*",
  269.               "sns:List*",
  270.               "sqs:Get*",
  271.               "sqs:List*",
  272.               "opsworks:Describe*",
  273.               "redshift:Describe*",
  274.               "kinesis:Describe*",
  275.               "kinesis:List*"
  276.             ],
  277.             "Resource": "*"
  278.           } ]
  279.         },
  280.         "Roles": [ { "Ref": "CFNRole" } ]
  281.       }
  282.     },
  283.  
  284.     "CFNInstanceProfile": {
  285.       "Type": "AWS::IAM::InstanceProfile",
  286.       "Properties": {
  287.         "Path": "/",
  288.         "Roles": [ { "Ref": "CFNRole" } ]
  289.       }
  290.     },
  291.  
  292.     "WebServer": {
  293.       "Condition": "DefaultVPC",
  294.       "Type": "AWS::EC2::Instance",
  295.       "Metadata" : {
  296.         "AWS::CloudFormation::Init" : {
  297.           "configSets" : {
  298.             "full_install" : ["base", "cloudformer"]
  299.           },
  300.           "base" : {
  301.             "packages" : {
  302.               "yum" : {
  303.                 "gcc"              : [],
  304.                 "gcc-c++"          : [],
  305.                 "make"             : [],
  306.                 "libxml2-devel"    : [],
  307.                 "libxslt-devel"    : [],
  308.                 "sqlite-devel"     : [],
  309.                 "patch"            : [],
  310.                 "readline"         : [],
  311.                 "readline-devel"   : [],
  312.                 "zlib"             : [],
  313.                 "zlib-devel"       : [],
  314.                 "libyaml-devel"    : [],
  315.                 "libffi-devel"     : [],
  316.                 "openssl-devel"    : [],
  317.                 "bzip2"            : [],
  318.                 "autoconf"         : [],
  319.                 "automake"         : [],
  320.                 "libtool"          : [],
  321.                 "bison"            : [],
  322.                 "ruby-devel"       : []
  323.               }
  324.             }
  325.           },
  326.           "cloudformer" : {
  327.             "sources" : {
  328.               "/home/ec2-user/cloudformer" : {"Fn::Join" : ["/", [
  329.                                               {"Fn::FindInMap" : ["Region2Examples", {"Ref" : "AWS::Region"}, "Examples"]},
  330.                                               "AWSCloudFormer041.zip" ]]}
  331.             },
  332.             "files" : {
  333.               "/home/ec2-user/setup_cloudformer" : {
  334.                 "content" : { "Fn::Join" : ["", [
  335.                   "#!/usr/bin/env bash\n",
  336.                   "cd /home/ec2-user/cloudformer\n",
  337.                   "# Setup the CloudFormer service\n",
  338.                   "mkdir -p vendor/bundle\n",
  339.                   "gem install --local /home/ec2-user/cloudformer/vendor/cache/rake-10.4.2.gem\n",
  340.                   "gem install --local /home/ec2-user/cloudformer/vendor/cache/bundler-1.7.11.gem\n",
  341.                   "gem install --local /home/ec2-user/cloudformer/vendor/cache/bundle-0.0.1.gem\n",
  342.                   "/usr/local/bin/bundle install --local --path /home/ec2-user/cloudformer/vendor/bundle\n",
  343.                   "/usr/local/bin/rake RAILS_ENV=production db:migrate\n",
  344.                   "gem install --local /home/ec2-user/cloudformer/vendor/cache/rack-1.6.0.gem\n",
  345.                   "gem install --local /home/ec2-user/cloudformer/vendor/cache/eventmachine-1.0.4.gem\n",
  346.                   "gem install --local /home/ec2-user/cloudformer/vendor/cache/daemons-1.1.9.gem\n",
  347.                   "gem install --local /home/ec2-user/cloudformer/vendor/cache/thin-1.6.3.gem\n",
  348.                   "# Create certificate and private key for SSL\n",
  349.                   "mkdir -p /home/ec2-user/cloudformer/.ssl\n",
  350.                   "cd /home/ec2-user/cloudformer/.ssl\n",
  351.                   "openssl genrsa -des3 -passout pass:\"" , { "Ref" : "Password" }, "\" -out server.pass.key 1024\n",
  352.                   "openssl rsa -passin pass:\"", { "Ref" : "Password" }, "\" -in server.pass.key -out server.key\n",
  353.                   "openssl req -new -key server.key -out server.csr -subj \"/C=US/ST=Washington/L=Seattle/O=Amazon Web Services/OU=CloudFormer\"\n",
  354.                   "openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt\n",
  355.                   "rm server.pass.key server.csr\n"
  356.                 ]]},
  357.                 "mode"  : "000755",
  358.                 "owner" : "root",
  359.                 "group" : "root"
  360.               },
  361.               "/home/ec2-user/cloudformer/config/initializers/user.rb" : {
  362.                 "content" : { "Fn::Join" : ["", [
  363.                   "USER_NAME = \"", { "Ref" : "Username" }, "\"\n",
  364.                   "PASSWORD = \"", { "Ref" : "Password" }, "\"\n"
  365.                 ]]},
  366.                 "mode"  : "000400",
  367.                 "owner" : "root",
  368.                 "group" : "root"
  369.               },
  370.               "/usr/bin/cloudformer" : {
  371.                 "content" : { "Fn::Join" : ["", [
  372.                   "#!/usr/bin/env bash\n",
  373.                   "cd /home/ec2-user/cloudformer\n",
  374.                   "/usr/local/bin/thin start -p 443 -e production -d --ssl --ssl-key-file /home/ec2-user/cloudformer/.ssl/server.key --ssl-cert-file /home/ec2-user/cloudformer/.ssl/server.crt\n"
  375.                 ]]},
  376.                 "mode"  : "000755",
  377.                 "owner" : "root",
  378.                 "group" : "root"
  379.               }
  380.             },
  381.             "commands" : {
  382.               "01_install_cloudformer" : {
  383.                 "command" : "/home/ec2-user/setup_cloudformer &> /var/log/setup_cloudformer.log",
  384.                 "cwd" : "/home/ec2-user/cloudformer"
  385.               },
  386.               "02_setup_boot" : {
  387.                 "command" : "echo '/usr/bin/cloudformer' >> /etc/rc.local",
  388.                 "cwd" : "/"
  389.               }
  390.             }
  391.           }
  392.         }
  393.       },
  394.       "Properties": {
  395.         "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" },
  396.                           { "Fn::FindInMap" : [ "AWSInstanceType2Arch", "t2.small", "Arch" ] } ] },
  397.                          
  398.                          
  399.            
  400.         "KeyName": {
  401.           "Ref": "KeyName"
  402.         },
  403.                          
  404.                          
  405.         "InstanceType"       : "t2.small",
  406.         "SecurityGroups"     : [ {"Ref" : "WebServerSecurityGroup"} ],
  407.         "IamInstanceProfile" : { "Ref" : "CFNInstanceProfile" },
  408.         "UserData"           : { "Fn::Base64" : { "Fn::Join" : ["", [
  409.           "#!/bin/bash -xe\n",
  410.           "yum update -y aws-cfn-bootstrap\n",
  411.  
  412.           "/opt/aws/bin/cfn-init -v ",
  413.           "         --stack ", { "Ref" : "AWS::StackId" },
  414.           "         --resource WebServer ",
  415.           "         --configsets full_install ",
  416.           "         --region ", { "Ref" : "AWS::Region" }, "\n",
  417.  
  418.           "/opt/aws/bin/cfn-signal -e $? ",
  419.           "         --stack ", { "Ref" : "AWS::StackId" },
  420.           "         --resource WebServer ",
  421.           "         --region ", { "Ref" : "AWS::Region" }, "\n"
  422.         ]]}}
  423.       },
  424.       "CreationPolicy" : {
  425.         "ResourceSignal" : {
  426.           "Timeout" : "PT30M"
  427.         }
  428.       }
  429.     },
  430.  
  431.     "WebServerCustomVPC": {
  432.       "Condition": "CreateNewVPC",
  433.       "DependsOn": "RouteVPCAny",
  434.       "CreationPolicy": {
  435.         "ResourceSignal": {
  436.           "Timeout": "PT30M"
  437.         }
  438.       },
  439.       "Metadata": {
  440.         "AWS::CloudFormation::Init": {
  441.           "base": {
  442.             "packages": {
  443.               "yum": {
  444.                 "autoconf": [],
  445.                 "automake": [],
  446.                 "bison": [],
  447.                 "bzip2": [],
  448.                 "gcc": [],
  449.                 "gcc-c++": [],
  450.                 "libffi-devel": [],
  451.                 "libtool": [],
  452.                 "libxml2-devel": [],
  453.                 "libxslt-devel": [],
  454.                 "libyaml-devel": [],
  455.                 "make": [],
  456.                 "openssl-devel": [],
  457.                 "patch": [],
  458.                 "readline": [],
  459.                 "readline-devel": [],
  460.                 "ruby-devel": [],
  461.                 "sqlite-devel": [],
  462.                 "zlib": [],
  463.                 "zlib-devel": []
  464.               }
  465.             }
  466.           },
  467.           "cloudformer": {
  468.             "commands": {
  469.               "01_install_cloudformer": {
  470.                 "command": "/home/ec2-user/setup_cloudformer &> /var/log/setup_cloudformer.log",
  471.                 "cwd": "/home/ec2-user/cloudformer"
  472.               },
  473.               "02_setup_boot": {
  474.                 "command": "echo '/usr/bin/cloudformer' >> /etc/rc.local",
  475.                 "cwd": "/"
  476.               }
  477.             },
  478.             "files": {
  479.               "/home/ec2-user/cloudformer/config/initializers/user.rb": {
  480.                 "content": {
  481.                   "Fn::Join": [
  482.                     "",
  483.                     [
  484.                       "USER_NAME = \"",
  485.                       {
  486.                         "Ref": "Username"
  487.                       },
  488.                       "\"\n",
  489.                       "PASSWORD = \"",
  490.                       {
  491.                         "Ref": "Password"
  492.                       },
  493.                       "\"\n"
  494.                     ]
  495.                   ]
  496.                 },
  497.                 "group": "root",
  498.                 "mode": "000400",
  499.                 "owner": "root"
  500.               },
  501.               "/home/ec2-user/setup_cloudformer": {
  502.                 "content": {
  503.                   "Fn::Join": [
  504.                     "",
  505.                     [
  506.                       "#!/usr/bin/env bash\n",
  507.                       "cd /home/ec2-user/cloudformer\n",
  508.                       "# Setup the CloudFormer service\n",
  509.                       "mkdir -p vendor/bundle\n",
  510.                       "gem install --local /home/ec2-user/cloudformer/vendor/cache/rake-10.4.2.gem\n",
  511.                       "gem install --local /home/ec2-user/cloudformer/vendor/cache/bundler-1.7.11.gem\n",
  512.                       "gem install --local /home/ec2-user/cloudformer/vendor/cache/bundle-0.0.1.gem\n",
  513.                       "/usr/local/bin/bundle install --local --path /home/ec2-user/cloudformer/vendor/bundle\n",
  514.                       "/usr/local/bin/rake RAILS_ENV=production db:migrate\n",
  515.                       "gem install --local /home/ec2-user/cloudformer/vendor/cache/rack-1.6.0.gem\n",
  516.                       "gem install --local /home/ec2-user/cloudformer/vendor/cache/eventmachine-1.0.4.gem\n",
  517.                       "gem install --local /home/ec2-user/cloudformer/vendor/cache/daemons-1.1.9.gem\n",
  518.                       "gem install --local /home/ec2-user/cloudformer/vendor/cache/thin-1.6.3.gem\n",
  519.                       "# Create certificate and private key for SSL\n",
  520.                       "mkdir -p /home/ec2-user/cloudformer/.ssl\n",
  521.                       "cd /home/ec2-user/cloudformer/.ssl\n",
  522.                       "openssl genrsa -des3 -passout pass:\"",
  523.                       {
  524.                         "Ref": "Password"
  525.                       },
  526.                       "\" -out server.pass.key 1024\n",
  527.                       "openssl rsa -passin pass:\"",
  528.                       {
  529.                         "Ref": "Password"
  530.                       },
  531.                       "\" -in server.pass.key -out server.key\n",
  532.                       "openssl req -new -key server.key -out server.csr -subj \"/C=US/ST=Washington/L=Seattle/O=Amazon Web Services/OU=CloudFormer\"\n",
  533.                       "openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt\n",
  534.                       "rm server.pass.key server.csr\n"
  535.                     ]
  536.                   ]
  537.                 },
  538.                 "group": "root",
  539.                 "mode": "000755",
  540.                 "owner": "root"
  541.               },
  542.               "/usr/bin/cloudformer": {
  543.                 "content": {
  544.                   "Fn::Join": [
  545.                     "",
  546.                     [
  547.                       "#!/usr/bin/env bash\n",
  548.                       "cd /home/ec2-user/cloudformer\n",
  549.                       "/usr/local/bin/thin start -p 443 -e production -d --ssl --ssl-key-file /home/ec2-user/cloudformer/.ssl/server.key --ssl-cert-file /home/ec2-user/cloudformer/.ssl/server.crt\n"
  550.                     ]
  551.                   ]
  552.                 },
  553.                 "group": "root",
  554.                 "mode": "000755",
  555.                 "owner": "root"
  556.               }
  557.             },
  558.             "sources": {
  559.               "/home/ec2-user/cloudformer": {
  560.                 "Fn::Join": [
  561.                   "/",
  562.                   [
  563.                     {
  564.                       "Fn::FindInMap": [
  565.                         "Region2Examples",
  566.                         {
  567.                           "Ref": "AWS::Region"
  568.                         },
  569.                         "Examples"
  570.                       ]
  571.                     },
  572.                     "AWSCloudFormer041.zip"
  573.                   ]
  574.                 ]
  575.               }
  576.             }
  577.           },
  578.           "configSets": {
  579.             "full_install": [
  580.               "base",
  581.               "cloudformer"
  582.             ]
  583.           }
  584.         }
  585.       },
  586.       "Properties": {
  587.         "IamInstanceProfile": {
  588.           "Ref": "CFNInstanceProfile"
  589.         },
  590.         "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" },
  591.                           { "Fn::FindInMap" : [ "AWSInstanceType2Arch", "t2.small", "Arch" ] } ] },
  592.         "InstanceType": "t2.small",
  593.         "SubnetId": {
  594.           "Ref": "VPCSubnet"
  595.         },
  596.         "SecurityGroupIds": [
  597.           {
  598.             "Ref": "WebServerSecurityGroup"
  599.           }
  600.         ],
  601.         "UserData": {
  602.           "Fn::Base64": {
  603.             "Fn::Join": [
  604.               "",
  605.               [
  606.                 "#!/bin/bash -xe\n",
  607.                 "yum update -y aws-cfn-bootstrap\n",
  608.                 "/opt/aws/bin/cfn-init -v ",
  609.                 "         --stack ",
  610.                 {
  611.                   "Ref": "AWS::StackId"
  612.                 },
  613.                 "         --resource WebServerCustomVPC ",
  614.                 "         --configsets full_install ",
  615.                 "         --region ",
  616.                 {
  617.                   "Ref": "AWS::Region"
  618.                 },
  619.                 "\n",
  620.                 "/opt/aws/bin/cfn-signal -e $? ",
  621.                 "         --stack ",
  622.                 {
  623.                   "Ref": "AWS::StackId"
  624.                 },
  625.                 "         --resource WebServerCustomVPC ",
  626.                 "         --region ",
  627.                 {
  628.                   "Ref": "AWS::Region"
  629.                 },
  630.                 "\n"
  631.               ]
  632.             ]
  633.           }
  634.         }
  635.       },
  636.       "Type": "AWS::EC2::Instance"
  637.     },
  638.  
  639.     "WebServerSecurityGroup" : {
  640.       "Type" : "AWS::EC2::SecurityGroup",
  641.       "Properties" : {
  642.         "GroupDescription" : "Enable HTTPS access via port 443",
  643.         "VpcId": {
  644.           "Fn::If" : [
  645.             "CreateNewVPC",
  646.             {"Ref" : "VPC"},
  647.             {"Ref" : "AWS::NoValue"}
  648.           ]
  649.         },
  650.         "SecurityGroupIngress" : [
  651.           {"IpProtocol" : "tcp", "FromPort" : "443", "ToPort" : "443", "CidrIp" : "0.0.0.0/0"}
  652.         ]
  653.       }
  654.     },
  655.     "VPC": {
  656.       "Condition": "CreateNewVPC",
  657.       "Type": "AWS::EC2::VPC",
  658.       "Properties": {
  659.         "Tags": [
  660.           {
  661.             "Key": "Name",
  662.             "Value": "CloudformwerVPC"
  663.           }
  664.         ],
  665.         "CidrBlock": "10.10.10.0/24",
  666.         "EnableDnsSupport": "true",
  667.         "EnableDnsHostnames": "true"
  668.       }
  669.     },
  670.     "VPCSubnet": {
  671.       "Condition": "CreateNewVPC",
  672.       "Type": "AWS::EC2::Subnet",
  673.       "Properties": {
  674.         "MapPublicIpOnLaunch": "true",
  675.         "AvailabilityZone": {
  676.           "Fn::Select": [
  677.             "0",
  678.             {
  679.               "Fn::GetAZs": {
  680.                 "Ref": "AWS::Region"
  681.               }
  682.             }
  683.           ]
  684.         },
  685.         "VpcId": {
  686.           "Ref": "VPC"
  687.         },
  688.         "CidrBlock": "10.10.10.0/24"
  689.       }
  690.     },
  691.     "VPCInternetGateway": {
  692.       "Condition": "CreateNewVPC",
  693.       "Type": "AWS::EC2::InternetGateway",
  694.       "Properties": {}
  695.     },
  696.     "VPCAttachGateway": {
  697.       "Condition": "CreateNewVPC",
  698.       "Type": "AWS::EC2::VPCGatewayAttachment",
  699.       "Properties": {
  700.         "VpcId": {
  701.           "Ref": "VPC"
  702.         },
  703.         "InternetGatewayId": {
  704.           "Ref": "VPCInternetGateway"
  705.         }
  706.       }
  707.     },
  708.     "VPCRouteTable": {
  709.       "Condition": "CreateNewVPC",
  710.       "Type": "AWS::EC2::RouteTable",
  711.       "Properties": {
  712.         "Tags": [
  713.           {
  714.             "Key": "Name",
  715.             "Value": "CloudformerVPCRouteTable"
  716.           }
  717.         ],
  718.         "VpcId": {
  719.           "Ref": "VPC"
  720.         }
  721.       }
  722.     },
  723.     "VPCSubnetRouteTableAssociation": {
  724.       "Condition": "CreateNewVPC",
  725.       "Type": "AWS::EC2::SubnetRouteTableAssociation",
  726.       "Properties": {
  727.         "SubnetId": {
  728.           "Ref": "VPCSubnet"
  729.         },
  730.         "RouteTableId": {
  731.           "Ref": "VPCRouteTable"
  732.         }
  733.       }
  734.     },
  735.     "RouteVPCAny": {
  736.       "Condition": "CreateNewVPC",
  737.       "Type": "AWS::EC2::Route",
  738.       "DependsOn": "VPCAttachGateway",
  739.       "Properties": {
  740.         "RouteTableId": {
  741.           "Ref": "VPCRouteTable"
  742.         },
  743.         "DestinationCidrBlock": "0.0.0.0/0",
  744.         "GatewayId": {
  745.           "Ref": "VPCInternetGateway"
  746.         }
  747.       }
  748.     }
  749.   },
  750.  
  751.   "Outputs": {
  752.     "CustomVPCWebsiteURL": {
  753.       "Description": "URL for CloudFormer",
  754.       "Value":
  755.       {
  756.         "Fn::Join":
  757.         [
  758.           "",
  759.           [
  760.             "https://",
  761.             {
  762.               "Fn::If" :
  763.               [
  764.                 "CreateNewVPC",
  765.                 {
  766.                   "Fn::GetAtt": [
  767.                     "WebServerCustomVPC",
  768.                     "PublicDnsName"
  769.                   ]
  770.                 },
  771.                 {
  772.                   "Fn::GetAtt": [
  773.                     "WebServer",
  774.                     "PublicDnsName"
  775.                   ]
  776.                 }
  777.               ]
  778.             }
  779.           ]
  780.         ]
  781.       }
  782.     }
  783.   }
  784. }
Advertisement
Add Comment
Please, Sign In to add comment