Transforming On-Prem CMS Software to SaaS on AWS Fargate
Written on
Chapter 1: Understanding the Challenge
To begin, let me share the challenge I'm facing: I need to convert an on-premises Content Management System (CMS) to a Software as a Service (SaaS) model in the cloud. The question arises: how can I achieve this?
To tackle this, I plan to utilize a GitHub project alongside a Docker image. The official GitHub repository provides all necessary files for building the image, or alternatively, we can opt for the official image available on Docker Hub.
Last week, I published a guide on how to download a Docker image and upload it to the AWS Elastic Container Registry (ECR). By having your own Docker image in a repository, you can proceed to deploy it on an ECS Fargate instance.
What Exactly is ECS Fargate?
ECS Fargate is essentially the serverless iteration of Amazon's Elastic Container Service (ECS). This means that the Docker containers are deployed on fully managed hosts by AWS, alleviating the maintenance responsibilities of developers and AWS users. With Fargate, you don't need to specify the precise EC2 instance types for running the containers, which simplifies the process significantly. Without Fargate, managing the resource allocation for Docker containers can become quite complex.
Defining ECR (Elastic Container Registry)
ECR is AWS's integrated, hosted, and managed registry for Docker images. You can build your images, upload them to ECR, and then make them available to ECS. While you can also use Docker Hub or other registries, ECR is particularly beneficial if you wish to utilize private container images while running services on AWS.
ECS Components Overview
The core components related to Docker in ECS include:
- Cluster: A collection of ECS container instances (in EC2 mode) or a logical grouping of tasks (in Fargate).
- Container Instance: An EC2 instance running the ECS agent, akin to the Docker daemon/agent.
- Service: Defines the purpose of your Docker tasks, including configurations like the task definition, the number of task instances to create, and the scheduling policy.
- Task Definition: Specifies the Docker image, resource requirements (CPU, memory), instance type, IAM roles, and boot command.
- Task Instance: An instance of a task definition, similar to running Docker on your own host.
What are Security Groups?
Security groups define how traffic is allowed to flow between different components. For instance, an Elastic Load Balancer (ELB) can accept connections from the internet and communicate with the container security group.
Starting the Project
To visualize our deployment infrastructure, we need several components:
- VPC (Virtual Private Cloud)
- RDS (Relational Database Service)
- ECR (Elastic Container Repository)
- EFS (Elastic File System)
- ECS (Elastic Container Service)
- CloudWatch
Since OpenCMS requires a MySQL database, I'll be setting up an RDS instance and using EFS for persistent file storage. We won't employ a Load Balancer for this configuration.
Building the VPC
We'll begin by constructing the VPC, which requires two subnets in separate Availability Zones. To create a VPC, follow these steps:
- In the dashboard, select "Create VPC."
- Choose "VPC and more" under VPC settings.
- Fill in the fields as follows:
- Enable auto-generated naming under "Name tag."
- Change the project name to "ADS VPC."
- Set the IPv4 CIDR block to 172.16.0.0/26.
- Select "No IPv6 CIDR block."
- Keep Tenancy as Default.
- Select 1 or 2 for Availability Zones based on your needs.
- Choose 2 for public subnets.
- Configure the public subnet CIDR block to 172.16.0.0/27.
- Click "Create VPC."
Once the VPC is established, we need to create Security Groups. We will be using three ports: MySQL (3306), EFS (2049), and Docker (8080).
Building the RDS Instance
To create an RDS database instance, follow these steps:
- If this is your first time, click "Get Started Now" or navigate to the RDS Dashboard.
- Select MySQL Community Edition.
- For production purposes, select "No" for this example.
- On the Specify DB Details page, input the following:
- DB Instance Class: db.t2.micro
- Multi-AZ Deployment: No
- Allocated Storage: 20GB
- DB Instance Identifier: RDSOpenCMS
- Master Username: admin
- Master Password: Choose a secure password and note it down.
After configuring the RDS instance, the next step is to set up the EFS file system.
Building the EFS Directory
Navigate to EFS and select "Create filesystem." Choose the previously created VPC and stick with the default settings for now. After the EFS file system is set up, we can proceed to configure the ECS.
Building the ECS Cluster
- Go to Amazon Elastic Container Service > Clusters.
- Click "Create a cluster."
- Fill in the details:
- Cluster name: OpenCMSCluster
- Networking: OpenCMS VPC
- Subnets: Both previously created subnets
- Infrastructure: AWS Fargate
Next, we need to create a task definition:
- Go to Amazon Elastic Container Service > Task Definitions and select "Create new task definition."
- Choose "Create new revision."
- Fill in the details:
- Task definition family: Name of the task
- Launch type: AWS Fargate
- OS, Architecture: Linux X86_64
- Task size: 2v, 4GB
- Container settings:
- Name: OpenCMS
- Image URI: <URI ECR image>
- Container port: 8080 | TCP | opencms-8080-tcp | HTTP
Once the Task Definition is complete, we will create a service to deploy automatic tasks.
Final Steps
After creating the service, you should see tasks being automatically generated. After a few minutes, you can connect to the container's IP address and access the OpenCMS interface.
If you found this guide helpful and would like to support me, consider buying me a coffee ☕️ through this BuyMeACoffee Link❤.
Thank you for reading through this guide! Please follow the author and this publication for more insights. Visit Stackademic to explore how we are democratizing programming education globally.
The first video, "Launch Docker Container on AWS Fargate," provides a practical overview of launching Docker containers using AWS Fargate.
The second video, "How To Set Up ECS Fargate And Deploy Your Docker Image Into AWS," walks you through the setup process for deploying Docker images with ECS Fargate.