In this case study, we'll show you how to develop and launch a simple e-Commerce service on AWS. We'll go over the architecture of the service and the different AWS services that are used. We'll also provide some code examples to help you get started.
The e-Commerce service that we'll be developing is a simple one that consists of a web front-end and a back-end database. The web front-end will be developed using the PHP programming language and the back-end database will be MySQL.
The web front-end will be hosted on an Amazon EC2 instance and will be accessed through an Amazon CloudFront distribution. CloudFront is a content delivery network (CDN) that will cache the static content of the website (such as images, CSS, and JavaScript files) and deliver it to users with low latency.
The back-end database will be hosted on Amazon RDS and will be used to store the products and orders data. RDS is a managed relational database service that makes it easy to set up, operate, and scale a relational database in the cloud.
The following AWS services will be used in this case study:
We'll start by setting up the back-end database. We'll be using Amazon RDS for MySQL.
First, we'll create a new RDS instance. We'll choose the MySQL engine and the db.t2.micro instance class.
Next, we'll configure the settings for the instance. We'll give the instance a name, choose the MySQL 5.6.x database engine, and select the db.t2.micro instance class.
Next, we'll create a new database. We'll give the database a name and choose the MySQL 5.6.x database engine.
Now that the database has been created, we'll need to create a user and grant the user access to the database. We'll create a user with the username "ecommerce" and the password "password".
Next, we'll grant the user access to the database. We'll select the "ecommerce" database and the "ecommerce" user and click the "Add" button.
Now that the back-end database has been set up, we'll need to set up the web front-end. We'll be using Amazon EC2 for this.
First, we'll create a new EC2 instance. We'll choose the Amazon Linux AMI and the t2.micro instance type.
Next, we'll configure the settings for the instance. We'll give the instance a name, choose the Amazon Linux AMI, and select the t2.micro instance type.
Now that the instance has been created, we'll need to SSH into the instance. We'll use the private key that we downloaded when we created the instance.
Once we're logged into the instance, we'll need to install the Apache web server, PHP, and the MySQL client. We'll do this using the yum package manager.
$ sudo yum install -y httpd24 php70 mysql56-client
Next, we'll start the Apache web server.
$ sudo service httpd start
Now that the web server is up and running, we'll need to create a new PHP file. We'll call this file "index.php" and we'll put it in the "/var/www/html" directory.
<?php
echo "Hello, world!";
?>
Now, we'll need to edit the "/etc/httpd/conf/httpd.conf" file and uncomment the following line:
LoadModule rewrite_module modules/mod_rewrite.so
Next, we'll restart the Apache web server.
$ sudo service httpd restart
Now, we'll need to create a new MySQL user. We'll use the "ecommerce" user that we created earlier. We'll grant the user access to the "ecommerce" database.
GRANT ALL ON ecommerce.* TO 'ecommerce'@'localhost' IDENTIFIED BY 'password';
Now that the user has been created, we'll need to import the data into the database. We'll use the "products.sql" file that is included in the GitHub repository.
$ mysql -u ecommerce -p ecommerce < products.sql
Now that the application is set up, we'll need to test it to make sure everything is working as expected. We'll start by accessing the application through a web browser.
As we can see, the application is working as expected. We can see the list of products and we can add items to the shopping cart.
Now that the application is up and running, we'll need to launch it. We'll do this by creating an Amazon CloudFront distribution.
First, we'll create a new CloudFront distribution. We'll choose the "Web" delivery method and the "Get" HTTP method.
Next, we'll configure the settings for the distribution. We'll give the distribution a name, select the "Web" delivery method, and choose the "Get" HTTP method.
Now, we'll need to create a new origin. We'll select the "Custom Origin" type and enter the URL for our EC2 instance.
Next, we'll configure the settings for the origin. We'll give the origin a name, select the "Custom Origin" type, and enter the URL for our EC2 instance.
Now, we'll need to create a new default cache behavior. We'll select the "Default (*)" path pattern and choose the "Allow All" option for the Forward Headers.
Next, we'll configure the settings for the default cache behavior. We'll select the "Default (*)" path pattern and choose the "Allow All" option for the Forward Headers.
Now, we'll need to create a new error page. We'll select the "404" error code and enter the URL for the error page.
Next, we'll configure the settings for the error page. We'll select the "404" error code and enter the URL for the error page.
Now, we'll need to create a new SSL certificate. We'll select the "Custom Certificate" option and enter the domain name for our website.
Next, we'll configure the settings for the SSL certificate. We'll select the "Custom Certificate" option and enter the domain name for our website.
Now, we'll need to create a new distribution. We'll select the "Web" delivery method and the "Get" HTTP method.
Next, we'll configure the settings for the distribution. We'll give the distribution a name, select the "Web" delivery method, and choose the "Get" HTTP method.
Now, we'll need to create a new default cache behavior. We'll select the "Default (*)" path pattern and choose the "Allow All" option for the Forward Headers.
Next, we'll configure the settings for the default cache behavior. We'll select the "Default (*)" path pattern and choose the "Allow All" option for the Forward Headers.
Now, we'll need to create a new error page. We'll select the "404" error code and enter the URL for the error page.
Next, we'll configure the settings for the error page. We'll select the "404" error code and enter the URL for the error page.
In this case study, we've shown you how to develop and launch a simple e-Commerce service on AWS. We've gone over the architecture of the service and the different AWS services that are used. We've also provided some code examples to help you get started.