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.

The project’s development was methodically divided into four phases to ensure a smooth implementation and optimal operational effectiveness:
Step 1: Open an Adobe Magento account and take advantage of all of its e-commerce features.
Step 2: Coordinate the AWS Cloud infrastructure configuration, utilizing Terraform to ensure an accurate and automated Infrastructure as Code (IaC) procedure.
Step 3: Use Ansible to automate and optimize the management workflow as you methodically configure and install the required software and packages.
Stage 4: Make sure the online store was optimized and prepared for consumer interaction by integrating and improving the e-commerce platform.
Step 1: Open an Adobe Magento account and take advantage of all of its e-commerce features.
The project’s first step was to register for an account on Magento’s Marketplace. Using the following website, I created a Magento account: https://marketplace.magento.com/ . After registering, the crucial step was to generate and safely store the Magento Public and Private API Keys. These keys are crucial since they are necessary for the e-commerce system’s security and functionality in its later setup and operation phases.

Public Key: 8a8a77b952fcc7033b7c46e331c9b93e
Private Key: 9d91f975845a654f6a4aa8d84041b569
Install Terraform on AWS Cloud Shell:
sudo yum install -y yum-utils
sudo yum-config-manager — add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
sudo yum -y install terraform
Download the Terraform files on AWS Cloud Shell
mkdir final_project
cd final_project
wget https://tcb-bootcamps.s3.amazonaws.com/bootcamp-aws/en/final-project-terraform.zip
unzip final-project-terraform.zip

Edit Terraform files | variable (same steps done in module 5):





Terraform Apply
terraform apply


EC2 instance

Part 2: Installing Ansible on EC2 instance
Connect to your EC2 instance via SSH:

Installing Ansible
sudo yum-config-manager — enable epel
sudo yum install ansible -y


Download the Ansible playbooks:
wget https://tcb-bootcamps.s3.amazonaws.com/bootcamp-aws/en/final-project-ansible-magento2.zip
unzip final-project-ansible-magento2.zip
Edit and save Ansible file parameters
cd ansible-magento2
vi group_vars/all.yml


- 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 (“Esc” | “:x”)

Ip address : 54.89.226.93
Public Key: 8a8a77b952fcc7033b7c46e331c9b93e → repo_api_key
Private Key: 9d91f975845a654f6a4aa8d84041b569 →repo_secret_key
Run Ansible to deploy the stack of tools for the e-commerce
ansible-playbook -i hosts.yml ansible-magento2.yml -k -vvv — become




- ‘HTML Head’ | Default page title: The Cloud Bootcamp Store
- ‘Header’ > Logo image: The Cloud Bootcamp logo from images
- ‘Header’ > Welcome text: Welcome to The Cloud Bootcamp Store!
- Save Configuration!
If requested “Refresh no Cache”, following these steps:
- Cache Refresh (Flush it) | Please go to ‘Cache Management’ and refresh cache types.
Configuration Status: INVALIDATED | Select it and Click on “Flush Magento Cache’
Otherwise, follow these customization e-commerce steps:
- Catalog > Products > Add product > The Cloud Bootcamp T-Shirt
- Price: 80
- Quantity: 100
- Images And Videos > Add images
- Save
- Content > Pages > Home Pages > Select | Edit
- Click Content > Erase content
- Insert Widget > Widget type: Catalog New Products List > Insert Widget
E-commerce deployment done successfully!
Remove the resources deployed via AWS Cloud Shell
sudo yum install -y yum-utils
sudo yum-config-manager — add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
sudo yum -y install terraform
Destroying resources:
cd ~/projeto_final/terraform/
terraform destroy
Terraform serves as a powerful Infrastructure as Code (IaC) tool, allowing teams to define and provision AWS resources in a declarative manner. With Terraform, infrastructure components such as EC2 instances, VPCs, RDS databases, and S3 buckets can be easily provisioned, modified, and scaled as needed. This enables rapid deployment of the E-Commerce System while maintaining infrastructure configuration as code, which enhances reproducibility and reduces the risk of configuration drift.
In conclusion, the implementation of an E-Commerce System on AWS using Terraform and Ansible represents a modern and efficient approach to infrastructure provisioning and application deployment, enabling organizations to achieve automation, scalability, and agility in their cloud environments.