Integration of Webhosting (WordPress)With AWS RDS using Ansible.
Introduction Of AWS -
AWS is a cloud that is provided by Amazon. Amazon Elastic Compute Cloud (Amazon EC2 ) is a part of Amazon.com’s cloud-computing platform, Amazon Web Services, that allows users to rent virtual computers on which to run their own computer applications. AWS EC2 service provisions resources like RAM, HardDisk. CPU etc.
What is AWS-RDS?
Amazon Relational Database Service (Amazon RDS) makes it easy to set up, operate, and scale a relational database in the cloud. It provides cost-efficient and resizable capacity while automating time-consuming administration tasks such as hardware provisioning, database setup, patching, and backups. It frees you to focus on your applications so you can give them the fast performance, high availability, security, and compatibility they need.
Amazon RDS is available on several database instance types — optimized for memory, performance, or I/O — and provides you with six familiar database engines to choose from, including Amazon Aurora, PostgreSQL, MySQL, MariaDB, Oracle Database, and SQL Server. You can use the AWS Database Migration Service to easily migrate or replicate your existing databases to Amazon RDS.
What is WordPress?
WordPress is open-source software, which means anyone can study its code and write their apps (plugins) and templates (themes) for it.
WordPress is the simplest, most popular way to create your own website or blog. In fact, WordPress powers over 39.5% of all the websites on the Internet. Yes — more than one in four websites that you visit are likely powered by WordPress.
On a slightly more technical level, WordPress is an open-source content management system licensed under GPLv2, which means that anyone can use or modify the WordPress software for free. A content management system is basically a tool that makes it easy to manage important aspects of your website — like content — without needing to know anything about programming.
The end result is that WordPress makes building a website accessible to anyone — even people who aren’t developers.
- Create a VPC
- Create two subnets in that VPC
a) Public subnet
b) Private subnet
3.Create one Internet Gateway and connect it to the public subnet.
4. Create a routing table for Internet Gateway, update and associate it with public subnet.
5. Create one Nat Gateway and connect it to the public subnet.
6. Create a routing table for Nat Gateway, update and associate it with private subnet.
7. Launch one ec2 instance in public subnet and configure it with wordpress.
8. Set up a MySQL server using AWS RDS service using Free Tier As WordPress stores data at the backend in the MySQL Database server.
For this, there are some Prerequisite
- IAM User with the required permission.
- Boto installed. (Ansible uses the Boto Python library to handle AWS management).
Step1: Create a ansible-vault for protect your credentials
ansible-vault create vars.yml
Step2: Create playbook to launch complete infrastructure.
To create a VPC, we have to use the ec2_vpc_net module. We will register the module returned data in the “vpc” variable.
b) Creating subnets
Now We would need to create a public subnet in ‘ap-south-1a”.
Now create a private subnet in “ap-south-1b”.
c) Create Internet Gateway for Public Subnet.
We need an IGW so that our public subnet can access the internet.
d) Create a route table for Internet Gateway
Now, we would need to route the traffic to the IGW via the route table.
e) Create keyPair
In this step, we will create an EC2 Key Pair so that we can connect to our instances.
f) Create Security Groups
Security group for “RDS”.
Security group for “WORDPRESS”.
g) Create RDS Subnet Group
We need to create Subnet Group to launch RDS in own VPC.
h) Launch RDS
Now Deploying RDS in private subnet.
i) Launching EC2 instance for configuring aws
For ec2 instance.
Here , I am copying my ec2 instance public ip in my inventory so that I can do ssh with my instance for configuring it with wordpress.
Step3: Create playbook to configure ec2 instance for wordpress.
Here, I have used Command module to run amazon-linux-extras for access the Extra Packages for Enterprise Linux (EPEL) repository to allow installation of packages that aren’t available in standard repositories.
Here “get_url” module download the wordpress file from internet in zip format . For extracting it I have used “unarchive” module I will extract the wordpress from the zip format.
Here I am passing template file which dynamically fetch the information about database name , database user name, databse password and database host id .
Now We can see clearly Our wordpress Configured Successfully .
Verifying through mysql :-
Now , We can see that Our wordpress data is stored in RDS.