Amazon Web Services (AWS) offers reliable, scalable, and inexpensive cloud computing in an on demand fashion. Their subscription based service is a departure from more traditional hosting business models. Not only do they offer the hosting basics but now offer a wide range of services all designed with specific uses in mind.
When it comes to hosting an ecommerce site, many of the flexible and scalable attributes of AWS become compelling for varying reasons. For example, what better way to handle that Black Friday traffic spike than having the ability to almost instantly scale your web server to handle the extra load.
Every ecommerce site is different and the type of solution needed varies immensely based on the project requirements however there are some staple components that are obvious candidates for Magento within the AWS suite.
In this article I am going to run through these basic building blocks, giving some more detail on their function and illustrate what a generic AWS / Magento architecture may look like.
This is not designed to be a catch all tutorial but rather a gentle introduction to using AWS to host Magento.
A departure from traditional hosting
First things first, let’s talk a little bit about how the AWS on demand business model differs from traditional hosting.
With traditional hosting models you would typically pay a fixed amount for a given period and for that price you would get a ‘bare metal’ server. If the capacity of that server was reached you would have the ability to add resource. This, in most cases would result in a new or revised contract with your provider and a few hours to days of time to allow the hosting company to action the upgrade.
Aside from the time cost to perform such an upgrade this presents an inherent problem: You are paying for more than you use.
The below diagram illustrates actual usage (in red) and a traditional hosting capacity (in blue)
When the server is not being fully utilised you are still paying as if it was. This is where AWS scaling comes into play. With the correct setup you can ensure that you are only paying for what you use.
Designing with scalability in mind
It is important at this point to acknowledge that every site is different. Sites can have anything from a few to millions of SKUs, different integration requirements as well as varying traffic levels.
Both affect the specification requirements of the hosting environment dramatically and how it may need to scale over time. That is why it is important to start first with the ongoing requirements and design the solution with this in mind, as such there is not such a thing as a one-size-fits-all solution.
Broadly speaking there are two ways to scale your infrastructure.
Vertically: By adding resource to the existing instance
Horizontally: By adding additional instances your existing one
There are pros and cons to both, for example vertical scaling means a single point of failure but is simple. Horizontal scaling adds complexity but has the big benefit of redundancy.
AWS also provides the ability to manually or with some extra effort, automatically scale your web server. This allows you to add new infrastructure all from the comfort of AWS’ robust control panel.
Auto scaling is outside of the scope of this article but knowing that the capability is there can be useful as your store grows.
An example AWS / Magento setup
With that covered let’s move onto some of the most useful AWS components, their function and how they can be used to host a Magento site.
Let's take a basic AWS Magento hosting architecture and delve into the components.
As per the above diagram the main components are
This is AWS’ web server offering. They come in a variety of shapes and sizes and what you select will depend heavily on your site requirements however the best place to start is the Magento docs on minimum specification requirements: https://devdocs.magento.com/guides/v2.2/install-gde/system-requirements-tech.html
When configuring an EC2 instance you have complete control of operating system (for Magento you should use Linux) as well as choice of hard drives and number of CPUs.
AWS also offer Amazon Machine Images (AMI) which are pre built templates of an entire web server stack making it easy to build the web server you require in a few simple steps.
RDS (Relational Database Service) is AWS’ database offering. It is an out of the box solution that allows you to configure databases without the burden of having to manage the software running on the instance directly. The idea being that it reduces some of the complexity associated with managIng the finer details yourself. It is a black box of sorts.
It also comes with some pretty useful features such as auto software upgrades, logging, snapshots and rollbacks.
In our case as we are hosting a Magento site we will need to install MySQL version 5.6 or above and use some AWS security groups in order to make sure it can effectively talk to your EC2 instance(s).
Now that the basic web server and database is we can go ahead and add some peripheral components in order to enhance the setup.
Magento’s built in caching helps to speed up the site by saving previous user’s data in a fast access cache and sparing load on the database.
By default this cache is stored on the web server file system along with user session data. This is ok but can often be slow due to the latency involved in reading and writing from disk. For that reason AWS offers a service that is specially optimised for delivering cached data at a faster rate: Elasticache.
In order to use this you will need to simply configure the Elasticache instances that you require and configure your Magento store to use this by modifying your main Magento config file. This will tell Magento where to fetch the cached data from.
It can also be used with the same benefit for storing site session data.
AWS Elasticache provides both Redis and Memcached databases so either or both can be used depending on your preferences.
Anyone who is serious about ecommerce should at least consider the use of a CDN in order to speed up the delivery of assets to the end user.
The CDN will ensure that static assets of your site are delivered to your end user quicker by placing them physically closer to them geographically.
It also has the extra bonus of reducing load on the web server itself.
This article covers the very basics but there are all sorts of ways you can architecture AWS for Magento from having multiple availability zones, adding in a front end cache like Varnish using AWS Elastic Load Balancer (ELB), the list goes on.
Hopefully this provides a starting point with a basic understanding of what is involved.
If you are interested in learning more then it is worth visiting AWS' guide to configuring their services for Magento: https://aws.amazon.com/quickstart/architecture/magento/
You can also read about how I can help you with your Magento and AWS hosting requirements here.