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

Filipe Pacheco
4 min readOct 20, 2023

--

Hello readers, today I completed my final project in the AWS bootcamp provided by The Cloud bootcamp. Although this is the last project in the AWS bootcamp, it won’t be my last post about AWS. The next bootcamp is in DevOps, and I will continue to use resources available on AWS. Don’t forget to follow me to stay updated.

Task of the day

In another project based on a real-world scenario, I worked as a Cloud Engineer using DevOps. In this project, I successfully implemented an e-Commerce platform in an MVP (Minimum Viable Product) state on AWS within less than 2 hours. I achieved this by leveraging Terraform and Ansible for automated provisioning and configuration management processes (Infrastructure as Code — IaC).

To automate the configuration management process, software installation, and package management of the EC2 instance, I utilized Terraform and Ansible. Additionally, I utilized Magento, PHP, MySQL, and Redis to complete this project.

Services used in this implementation.

Implementation step by step

In the image below, you can see the proposed Solution Architecture for deploying an MVP for an e-commerce platform. Upon analyzing the architecture, it becomes evident that it is quite simple. It utilizes an EC2 instance within a VPC to ensure external access from the internet. While the architecture itself may not seem overly complex, the implementation’s intricacy lies in configuring the EC2 instance, due the packages hosted in it.

Solution Architecture proposed.

Terraform

As I cover this post about Terraform, I won’t go into too much detail. However, it’s important to note that Terraform is a technology responsible for automating the deployment, management, and removal of resources in cloud providers like AWS. Once again, I’m utilizing Terraform to set up the infrastructure necessary to host and simulate this e-commerce platform.

Within the Terraform file, I have configured two resources: the creation of the EC2 instance and the VPC configuration. Additionally, I have included Security Group rules for inbound and outbound communication, enabling connectivity between the EC2 instance and the MySQL database, and the EC2 and with the internet.

Ansible

This is a new software that I have yet to cover. Ansible is another powerful tool that follows the philosophy of Infrastructure as Code (IaC). It allows you to handle provisioning, configuration management, and application deployment seamlessly. While Terraform focuses on cloud providers, Ansible excels in specific environments like an EC2 instance, where it can effortlessly install, configure, and deploy software packages to host applications.

In this particular application, the Ansible playbook takes charge of downloading, installing, and configuring various components such as Magento (an e-commerce platform), PHP, MySQL (database), and Redis (in-memory data structure store).

With Ansible’s playbook, you can easily configure essential parameters such as ports, usernames, passwords, and more. As Noah Gift and Alfredo Deza emphasize in their book, Practical MLOps, “what can be automated, will be automated”. Ansible epitomizes this principle.

I continue to be impressed by the immense power of this tool. Even if you don’t have a large number of EC2 instances to deploy, Ansible and Terraform can still save you a considerable amount of time if you need to recreate similar infrastructures for other projects.

AWS CloudShell

You may are questioning yourself about, how this Terraform file and Ansible playbook are “played”, well the answer lies on AWS CloudShell. CloudShell is the place where you can interact programatically, CLI — command line interface, with AWS. Using it is possible to upload file or download using a Wget method, ahh CloudShell works on Linux, a AWS modified Linux. The commands necessary to allow you to interact can be discovered consulting the documentation of Terraform and Ansible.

You may be wondering how the Terraform file and Ansible playbook are executed. Well, the answer lies in the AWS CloudShell. CloudShell provides a programmatic, command-line interface (CLI) where you can interact with AWS. It allows you to upload and download files using methods like Wget. It’s worth noting that CloudShell operates on a modified Linux environment provided by AWS. To discover the specific commands required to interact with Terraform and Ansible, consulting their respective documentation is highly recommended.

The application

After performing the Terraform build action and running the Ansible playbook, the e-commerce platform hosted by Magento is now up and running. You can access it through the Public IP of the EC2 instance. Below is an image of the application, along with a message specifically for you, the Medium reader ;).

E-commerce MVP application.

Conclusion

In conclusion, by leveraging Terraform and Ansible in AWS, I successfully set up and deployed an e-commerce platform using Magento. Through Infrastructure as Code, I automated the provisioning, configuration, and deployment processes, saving valuable time and effort.

This concludes the first part of my MultiCloud practitioner upskilling journey. I have gained valuable knowledge thus far, but this is just the beginning of my learning path. In the next bootcamp, I will dive into the world of DevOps using AWS. I hope you have enjoyed the content thus far, as there is much more to come.

--

--

Filipe Pacheco

Senior Data Scientist | AI, ML & LLM Developer | MLOps | Databricks & AWS Practitioner