QueTwo's Blog

thouoghts on telecommunications, programming, education and technology

CFML in the Cloud (Part 2)

This is the second part of a two part series on deploying your CFML applications to the cloud using Amazon Web Services’ Elastic Beanstalk.  Read the first part here.

Updating your application

  1. Since your app is running through your Elastic Beanstalk, making changes are not as easy as just FTPing a few files to the server.  You will have to make the changes the “Java” way.
  2. Make the changes, and preview them on your local Tomcat server.  Drop the changed CFML templates into that WebContent directory, and hit refresh in your browser.
  3. Once your changes are good on your local machine, right click on the project name, go to Run A -> On Server…
  4. Choose your AWS instance from the list, and click Next.
  5. Make sure your project is still selected to deploy and click Finish.
  6. Wait.  It will take up to 5 minutes to upload your changes to AWS.  It will then take another 5 minutes or so to merge your changes with the original project and restart Tomcat.  It will take some time, so grab a fresh drink.  You may get an error message saying that your instance took too long to start — that’s ok.  Give it a few minutes and refresh your browser to see the new version.

Setting up a Database

  1. Amazon Web Services has the ability to host regular databases as well!  You have two options:
    1. Create a new database using Amazon RDS.  This gives you much more flexibility and lets you choose between MySQL, Oracle, or Microsoft SQL.   You get one year free for one DB instance.  You can have as many tables and store as much data as you want.  You can also tell it to do automatic backups and snapshots of your DB.  This is slower for smaller queries (because it relies on TCP sockets across the network), but faster for more CPU intensive queries.
    2. Create a DB within your Elastic Beanstalk instance.  This adds no cost to your application, but limits your DB choices.  It also means that if you re-create / re-upload your application, your DB will be reset.  This is slightly faster for smaller queries, but slower for larger, more CPU intensive queries.
  2. Head over to the Amazon Management Console.  Login.
  3. If you are going with option 1, do the following :
    1. Head to the RDS section.
    2. Launch a new instance.  Choose your DB engine.
    3. Set the Instance class (this is how much CPU you will have dedicated to the DB.  t1.micro is the free one).  Choose how much space you plan to use (allocation space), and set a DB name, username and password.
    4. Go through the rest of the configuration settings and launch your DB.  It will take about 5 minutes to it to fully launch.  Once it is launched, it will give you the “endpoint”, which is the hostname of the DB.  Write this down, you will need it later.
    5. Head over to the “DB Security Groups” section.  We need to allow our server to access this DB through the firewall.
    6. Click on Default.  Under Connection Type, choose EC2 Security Group, Choose the weird looking “instance id” from the drop-down, and click Add.
    7. You may want to add your own computer to the list as well so you can manage the DB over the internet — Add your IP address by using the CIDR connection type (it will tell your computer’s IP address so you can add it properly).
    8. Your DB should be all setup.  You can connect to it from your computer using your favorite admin tool — use the endpoint as the hostname, and the login/password/db name to connect to it.
  4. If you are going with option 2, do the following :
    1. Head over to the Elastic Beanstalk section.
    2. Find your application, then the environment you launched.
    3. Click Edit Configuration under the enviroment.
    4. Go to the Database tab, and fill out the following form : 
    5. When you apply changes, it will create the DB and spin it up.  This will take a few minutes.  You will get the endpoint (hostname), the username and password when it is finished.
    6. Head to the RDS section within the AWS Management Console.
    7. Head over to the “DB Security Groups” section.  We need to allow our server to access this DB through the firewall.
    8. Click on Default.
    9. Add your own computer to the list as well so you can manage the DB over the internet — Add your IP address by using the CIDR connection type (it will tell your computer’s IP address so you can add it properly).
    10. Your DB should be all setup.  You can connect to it from your computer using your favorite admin tool — use the endpoint as the hostname, and the login/password/db name to connect to it.
  5. Go to the Railo or ACF administration interface, and add the DB.

Using the Administration Interface (Railo Specific)

  1. Chances are, you want to be able to keep your configuration settings in sync between your local computer and the AWS instance.  This is not hard, but it requires you copying some files around.  In all honesty, this is the trickest thing about running Railo in the cloud…
  2. Head over to http://localhost:8080/<projectname>/railo-context/admin/server.cfm
  3. Set a password.  The first time you go to this page, it will ask you to set one.
  4. Make your changes.  For example, setup your databases, etc.
  5. Click on the Web Administrator tab.  At least set a password.  This is the context-specific settings (you only have one context at this time, so you may want to set everything in the server admin).
  6. When finished, click back on Server Administration.  This will take you back to the dashboard.  Keep this open in the background.
  7. Back in ColdFusion Builder, create a set of new folders within the WebContent folder :
    1. WebContent\WEB-INF\lib\railo-server\context\
    2. WebContent\WEB-INF\railo\
  8. Go back to the Server dashboard.  Find the configuration file section.  Find this file on your file system, and copy it into your new \WebContent\WEB-INF\lib\rail0-server\context\  directory.  4-9-2013 9-13-51 PM
  9. Go back to the Web Administrator dashboard.  Find the configuration file section.  Find this file on your file system, and copy it into your new \WebContent\WEB-INF\railo\ directory.
  10. Any time you want to push Railo configuration file changes into the cloud, you need to repeat this process.
  11. Deploy these changes to your AWS instance by following the Updating your Application section.  Your online AWS instance will be updated in a few minutes.

Licensing Considerations (Railo vs. Adobe ColdFusion)

One thing to consider when deploying your CFML application out to the cloud is licensing.  In particular, if you are using Adobe ColdFusion there are some serious licensing implications.  NOTE:  I’m no lawyer — I only play one on TV.  Consult your legal weasel team before trusting what I say here. 

If you deploy Railo on the cloud, there is very little you have to worry about.  By being licensed under the GNU Lesser license, you are free to do pretty much what you want with it.  You can deploy, scale up, scale down, etc. without much worry.  I promise.  Oh, and the Railo team is pretty nice too ;)

If you plan on working with Adobe ColdFusion 9.x and below, know you are breaking license agreement by using AWS.  They calculate your license by the number of CPUs that you are running on.  There is no way to know that.  At all.  You could say that you are trying to be honest by having one license per instance — and I’m sure they would believe you, but you are “breaking the law.”    I’ve tested this setup with ACF 8.x, ACF 9.x and ACF 10.x (all developer editions of the WAR deployment, of course!) and had it work fine.  ACF 8.x is pretty slow on t1.micro, so be aware of that.

If you plan on working with Adobe ColdFusion  10.x, they do allow for ACF on the cloud.  You can run either 1 CF Standard  instance per license, or up to 10 CF Enterprise instances per license.  More information is available on the blog post written on the subject by the CF team.  Read the blog post carefully.  What it boils down to is if you are running a standard license, you CANNOT use the auto-scaling features of Elastic Beanstalk.  If you are running an enterprise license, you need to watch the number of licenses you are consuming at your max when scaling up, and the amount of CPU you plan on consuming.

Conclusion

I hope this tutorial helped you bring your apps to the cloud.  As I said earlier, I’ve been deploying many of my customers using this method with great success.  Please comment below if you have any questions or comments with the setup.  Enjoy!

About these ads

3 responses to “CFML in the Cloud (Part 2)

  1. Pingback: CFML in the Cloud (Part 1) | QueTwo's Blog

  2. Phil April 11, 2013 at 10:42 am

    Great article(s). Can you comment on the cost of running this type of setup? I’m curious how this compares with other hosting options (i.e., shared, dedicated, VPS)

    • quetwo April 11, 2013 at 7:16 pm

      The first year of a new account is free for the computing time — they only charge for storage and transfer. In my case (a website with moderate use), it came to about $1.25/month.
      Each month after the first year ends up costing about $25/month – $30/month for me including the DB. Amazon has a calculator on their website (http://aws.amazon.com) to let you figure out how much it would cost with your own estimates.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 27 other followers

%d bloggers like this: