Implementation of an E-Commerce System on AWS in an automated way using Terraform and Ansible

In another project based in a real-world scenario, I worked as Cloud Engineer using DevOps, where I created and implemented an e-Commerce MVP (Minimum Viable Product) on AWS in less than 2 hours and 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 also used Magento, PHP, MySQL, and Redis to complete this project.

Implementation:
Part 1: E-commerce MVP deployment
1- Create Magento free account on, https://marketplace.magento.com/
- Create and Save the Public and Private Key from your Magento account.
2- Install Terraform on AWS Cloud Shell
- Replace the required fields such as VPC ID and EC2 type.
- We use larger t3a.large EC2 to support Magento application.
- Run Terraform deployment file.
Part 2: Installing Ansible on EC2 instance.
1- Connect to your EC2 instance via SSH.
2- Installing Ansible.
3- Download the Ansible playbooks
4- Edit and save Ansible file parameters:
- magento_domain: ec2-public-ip
- server_hostname: ec2-public-ip
- repo_api_key: b2041f02509880fbbb96312b29995cb6 (insert your public key)
- repo_secret_key: 7be7c69e79bd798a2a8a6b00988a5b72 (insert your private key)
Save the file.

5- Run Ansible to deploy the stack.

6- Testing E-commerce Website:
- Just copy and paste the EC2 Public IP in the browser.
- in some cases, it can take few minutes to finish installation and site up and running.
You will see the stack installation and configuration status as Ok.

Part 3- Configuring E-commerce:
The E-Commerce website has two main section. Customer page and store administrator CMS portal.
1- Got to http://EC2_PUBLIC_IP/securelocation (web configuration/admin portal).

- Enter your credentials.
- Upload your images and personalize the website.
o In the content configuration change the store logo, title etc. and save.
o If prompted “Refresh no Cache”, in the configuration status, select the INVALIDATED configuration and click on “Flush Magento Cache”. E-commerce application use cache extensively for optimal performance, therefore, it requires flush to release cache for content.
- Upload a picture and price your item (in my case a T-shirt).
o Go to catalogue, product, add product, change the content, upload the image/video etc. and save.
o We can use widgets to make the contents either static or dynamic to CMS pages. In this demo, I used the “Catalogue new product list”, that lists newly listed products in the CMS page. From the content page we can insert a widget.
2- Check if customization has taken effect by going to ‘customer view’.

Conclusion and Key Insights:
Numerous retail establishments leverage Magento E-commerce as their chosen platform for online store management. Despite the scale of this project being relatively modest, the deployment and management procedures remain consistent with larger implementations. A crucial takeaway from this endeavor is the seamless integration of Terraform and Ansible, orchestrating the automation of components in a sequential manner conducive to agile development practices. A comprehensive understanding of Ansible’s playbooks and the orchestrated execution of the technology stack is imperative. In summary, this project affords a profound overview and practical experience in deploying and testing an E-commerce website Minimum