Automated implementation of E-Commerce System on AWS

Deployed the EC2 instance usingTerraform.
Ansible to automate the process of e-commerce provisioning.

Atul Saxena
5 min readJul 5, 2023

Project Overview

I have worked as Cloud Engineer on this project based on a real-world scenario, where I created and implemented an e-Commerce MVP (Minimum Viable Product) on AWS in an automated way using Terraform and Ansible (Infrastructure as Code — IaC).

I provisioned the infrastructure in an automated way using Terraform and Ansible to automate the configuration management process, software installation, and package management of the EC2 instance. I have also used Magento, PHP, MySQL, and Redis to complete this project.

Mission: 👉 The CTO of The Cloud Bootcamp asked us to deploy an e-commerce system in the AWS Cloud in less than 2 hours. We need to validate whether it is a viable product for the market.

e-coomerce MVP deployment

Process

I broke up the solution of this process into two parts,

i. Create the environment and deploy EC2 instance in our AWS environment using Terraform. We make sure that security rules of the security groups are also in place. So that the client can access e-commerce website after it gets running.

Deploying EC2 instance on AWS using Terraform

ii. When EC2 is running, Ansible will automatically install Magento, PHP, MySQL, and Redis inside the host. Or you can say that Ansible installing the software stack in a fully automated way inside the EC2 instance we have created.

Ansible installing the software stack inside the EC2 instance

First Part of implementation

I have created a free Magento account and downloaded the software so that I can use it whenever we need it. The next step was to signup to download both public and private keys.

I have started provisioning the infrastructure on AWS by opening a cloud shell.

Opening a cloud shell

Now, I installed terraform on AWS cloud shell as shown below:

Terraform installed on AWS

After that, I configured the ‘main.tf’ file by updating VPC and ssh-key

update ‘vpc_id’ and ‘key_name’
updating both vpc_id and key_name

Once the configuration was complete, I deployed the EC2 VM. I ran the following command in this order

  1. terraform init
    -> To initialize the terraform environment
  2. terraform plan
    -> To review the execution plan and check for any p
  3. terraform apply
    -> To apply the changes and deploy the EC2 VM based on terraform configuration.

If you go to EC2 Console on AWS, you will find that it has created one EC2 instance

EC2 Instance

Created Security Group:

Security Group

Second Part of implementation

In this part, I have deployed the software stack using Ansible inside the EC2 instance.
→ Connect to EC2 instance remotely via SSH
For this, I copied the Public IP Address from EC2 Instance shown below:

Copied the Public IP Address

Next, I opened the Mac terminal and changed to the directory containing the file, ‘sshkey1.pem’, and connected to the EC2 instance by using the following command

Then, I proceeded to install Ansible and downloaded the Ansible playbooks.

Installation of Ansible

I made necessary changes in the all.yml in the groups_vars directory, like values of magento_domain, server_hostname, repo_api_key, and repo_secret_key

Here are the necessary changes I made.

I ran the Ansible Playbook command so that Ansible started deploying software in an automated way. Ansible has completed all the tasks as shown below:

Ansible has deployed all the required software

Copied the public IP Address from the EC2 instance shown below

EC2 Instance

Set up the e-commerce by using the following URL:

http://3.93.36.8/securelocation

I logged on to Magento by using admin credentials

I made a few changes in

  1. Content Page by uploading logo and welcome messages
  2. Added item, The Cloud Bootcamp T-Shirt, in the new Product page with Price, Quantities, Images
  3. Home Pages, Inserted Widget with widget type: Catalog New Products List

On the Home Page, click on the image as shown below

Click Add to Cart in the following image

Click Proceed to Checkout Button as shown below

After entering the Name, Address, and contact information, click the place order button.

The last part was to remove the resources by using destroy command.

It will remove EC2 Instance and security groups etc.

Hope you enjoyed reading my hands-on project. Please claps for me, provide feedback and follow me.

--

--

Atul Saxena
Atul Saxena

Written by Atul Saxena

The latest technologies with the truth | Formerly worked at Fortune 500 companies

No responses yet