How to create a CloudFormation template for MySQL?

How to create CloudFormation template for setting up WordPress on one instance and MySQL on another EC2 instance?

I used this part for MySQL, but doesn’t work, please give a suggestion… thank you.

"DatabaseServer" : {
  "Type": "AWS::EC2::Instance",
  "Metadata" : {
"AWS::CloudFormation::Init" : {
  "config" : {
    "packages" : {
    "yum" : {
       "mysql"        : [],
               "mysql-server" : [],
               "mysql-devel"  : [],
               "mysql-libs"   : []
    }
    }   
  },

 "services" : {
      "sysvinit" : {  
            "mysqld"   : { "enabled" : "true", "ensureRunning" : "true" }
          }
    }
  }
},

Related posts

Leave a Reply

2 comments

  1. AWS CloudFormation offers a large list or sample AWS CloudFormation Templates, which you can start/test easily from the AWS Management Console. There are several MySQL based solutions available, including a dedicated one for WordPress as well as a generic LAMP stack, in particular:

    I recommend to explore the selected template(s) and continue from there by tailoring it to your needs, e.g. by splitting the single EC2 instance into two (though I’d highly recommend to use a solution based on an Amazon RDS for MySQL database instead, which is much more robust and easier to handle for starters, for only slightly increased cost).

  2. To create a MySQL RDS instance with CFN you need to use the resource AWS::RDS::DBInstance with mysql engine and the wanted EngineVersion. There are some others props that you need to initialize that are not specific for MySQL Instance.
    You can use Altostra Designer to create the CFN template super quick.