prscrew.com

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:

  1. In the dashboard, select "Create VPC."
  2. Choose "VPC and more" under VPC settings.
  3. 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.
  4. 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:

  1. If this is your first time, click "Get Started Now" or navigate to the RDS Dashboard.
  2. Select MySQL Community Edition.
  3. For production purposes, select "No" for this example.
  4. 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

  1. Go to Amazon Elastic Container Service > Clusters.
  2. Click "Create a cluster."
  3. 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:

  1. Go to Amazon Elastic Container Service > Task Definitions and select "Create new task definition."
  2. Choose "Create new revision."
  3. 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.

Share the page:

Twitter Facebook Reddit LinkIn

-----------------------

Recent Post:

Essential Techniques for Data Preprocessing in Machine Learning

Discover essential data preprocessing techniques for machine learning, including encoding, imputation, and scaling, with practical examples.

Essential Python Practices for Daily Production Projects

Discover effective strategies for structuring Python projects, including real-world applications and best practices.

Optimizing Your Website's SEO Affordably: 5 Essential Tips

Discover five cost-effective methods to enhance your website's SEO and boost your online visibility without overspending.

Understanding Anxiety: Cognitive and Behavioral Insights

Explore the cognitive and behavioral aspects of anxiety and effective coping strategies.

Uncovering and Transforming Your Perception: A Guide

Discover how to assess and reshape your perception through self-reflection and intentional changes in your environment.

Embracing David Goggins' Philosophy: The Importance of Daily Balance

Discover how David Goggins’ insights on daily challenges can help maintain a positive mindset and balance in life.

Exploring Memory and Nootropics: A Journey into Cognitive Enhancement

Delve into the fascinating world of memory, Jill Price's unique condition, and the pursuit of cognitive enhancement through nootropics.

The Improbable Halt of AI Development: A Reality Check

A look into why a pause on AI development is unrealistic and the implications for society.