Cfn

 view release on metacpan or  search on metacpan

t/cfn_json/Rails_Multi_AZ.json  view on Meta::CPAN

            }
          }
        }
      },
      "Properties": {
        "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" },
                          { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] },
        "InstanceType"   : { "Ref" : "InstanceType" },
        "SecurityGroups" : [ {"Ref" : "WebServerSecurityGroup"} ],
        "KeyName"        : { "Ref" : "KeyName" },
        "UserData"       : { "Fn::Base64" : { "Fn::Join" : ["", [
          "#!/bin/bash -v\n",
          "yum update -y aws-cfn-bootstrap\n",

          "# Helper function\n",
          "function error_exit\n",
          "{\n",
          "  /opt/aws/bin/cfn-signal -e 1 -r \"$1\" '", { "Ref" : "WaitHandle" }, "'\n",
          "  exit 1\n",
          "}\n",

          "# Install Rails packages\n",
          "/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackId" }, " -r LaunchConfig ",
          "    --region ", { "Ref" : "AWS::Region" }, " || error_exit 'Failed to run cfn-init'\n",

          "# Install any other Gems, create the database and run a migration\n",
          "cd /home/ec2-user/sample\n",
          "export PATH=$PATH:/usr/local/bin\n",
          "bundle install  || error_exit 'Failed to install bundle'\n",
          "rake db:migrate || error_exit 'Failed to execute database migration'\n",

          "# Startup the rails server\n",
          "rails server -d\n",
          "echo \"cd /home/ec2-user/sample\" >> /etc/rc.local\n",
          "echo \"rails server -d\" >> /etc/rc.local\n",

          "# All is well so signal success\n",
          "/opt/aws/bin/cfn-signal -e 0 -r \"Rails application setup complete\" '", { "Ref" : "WaitHandle" }, "'\n"

        ]]}}
      }
    },

    "WaitHandle" : {
      "Type" : "AWS::CloudFormation::WaitConditionHandle"
    },

    "WaitCondition" : {
      "Type" : "AWS::CloudFormation::WaitCondition",
      "DependsOn" : "WebServerGroup",
      "Properties" : {
        "Handle"  : {"Ref" : "WaitHandle"},
        "Timeout" : "1500",
        "Count"   : { "Ref" : "WebServerCapacity" }
      }
    },

    "WebServerSecurityGroup" : {
      "Type" : "AWS::EC2::SecurityGroup",
      "Properties" : {
        "GroupDescription" : "Enable HTTP access via port 3000 locked down to the load balancer + SSH access",
        "SecurityGroupIngress" : [
          {"IpProtocol" : "tcp", "FromPort" : "3000", "ToPort" : "3000", "SourceSecurityGroupOwnerId" : {"Fn::GetAtt" : ["ElasticLoadBalancer", "SourceSecurityGroup.OwnerAlias"]},"SourceSecurityGroupName" : {"Fn::GetAtt" : ["ElasticLoadBalancer", "So...
          {"IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : { "Ref" : "SSHLocation"}}
        ]
      }
    },

    "DBSecurityGroup": {
      "Type": "AWS::RDS::DBSecurityGroup",
      "Properties": {
        "GroupDescription": "Grant database access to web server",
        "DBSecurityGroupIngress": [
          { "EC2SecurityGroupName": { "Ref": "WebServerSecurityGroup" } }
        ]
      }
    },

    "MySQLDatabase": {
      "Type": "AWS::RDS::DBInstance",
      "Properties": {
        "Engine" : "MySQL",
        "DBName" : { "Ref": "DBName" },
        "MultiAZ" : { "Ref": "MultiAZDatabase" },
        "MasterUsername": { "Ref": "DBUsername" },
        "MasterUserPassword": { "Ref" : "DBPassword" },
        "DBInstanceClass": { "Ref" : "DBInstanceClass" },
        "DBSecurityGroups": [ { "Ref": "DBSecurityGroup" } ],
        "AllocatedStorage": { "Ref" : "DBAllocatedStorage" }
      }
    }
  },

  "Outputs" : {
    "WebsiteURL" : {
      "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "ElasticLoadBalancer", "DNSName" ]}]] },
      "Description" : "URL for newly created Rails application"
    }
  }
}



( run in 5.844 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )