Skip to main content

ECS Fargate

This guide provides a step-by-step approach to deploying GoRules, a containerized application, using AWS ECS (Elastic Container Service) Fargate and Aurora Serverless. The deployment strategy outlined here aims to achieve a scalable, cost-effective, and easily maintainable infrastructure.

Overview of Components

  1. GoRules BRMS: Our containerized application
  2. AWS ECS Fargate: Serverless compute engine for containers
  3. Aurora Serverless v2: Auto-scaling relational database

In the following sections, we'll cover the configuration of each component, networking setup, security considerations, and deployment process. This guide assumes familiarity with AWS services, Docker, and general DevOps practices.

Database - Setting Up Aurora Serverless

1. Initiate Database Creation

  1. Log in to your AWS Management Console
  2. Navigate to the RDS (Relational Database Service) dashboard
  3. Click on “Create database” button

2. Choose Engine Options

  1. Select “Standard Create”
  2. Select “Aurora (PostgreSQL-Compatible)” as the engine type
  3. Under the templates, choose “Production” or “Dev/Test” depending on the environment

AWS Engine Options

3. Set-up Database Credentials

  1. Set “DB cluster identifier” (e.g., gorules-aurora-pg-cluster)
  2. Enter a master username (e.g., gorules_admin)
  3. Manually create a strong password
  4. Store this password securely; you'll need it later as an environment variable

AWS Credentials

4. Configure Database Instance

  1. For “Capacity settings”, choose “Serverless”
  2. Set the minimum and maximum Aurora Capacity Units (ACUs) based on your expected workload

AWS Database Instance

5. Configure Network & Security

  1. Choose the appropriate VPC for your ECS Fargate deployment
  2. Select or create a new DB Subnet Group
  3. For “Public access”, choose “No” unless your architecture requires it
  4. Create or select a VPC security group that allows inbound traffic on the Aurora port (default 5432 for PostgreSQL) from your ECS tasks

6. Additional Configuration

  1. Set the initial database name (e.g., gorules_db)
  2. Configure backup retention period as needed
  3. Enable encryption at rest (recommended)
  4. Enable deletion protection (recommended)

7. Finalize and Create

  1. Review all settings
  2. Click “Create database” at the bottom of the page

8. Wait for Completion

  1. The creation process may take several minutes
  2. You can monitor the progress in the RDS dashboard

9. Retrieve Connection Information

  1. Once the database is available, note down the endpoint
  2. This endpoint will be used in your application's connection string

Next steps

  • Store the manually generated master password as an environment variable or in AWS Secrets Manager.
  • Update your GoRules application configuration to use the new PostgreSQL database endpoint and credentials.
  • Test the connection from your local environment to ensure proper setup

Remember to never commit sensitive information like database passwords to your version control system. Always use environment variables or a secure secrets management solution in your deployment process.

Container Runner - Setting Up ECS Fargate

1. Create ECS Cluster

AWS Cluster List

  1. Navigate to the ECS dashboard in the AWS Management Console
  2. Click “Create cluster”
  3. Choose “AWS Fargate” under infrastructure
  4. Set Cluster name (e.g., gorules-cluster)
  5. Optionally enable CloudWatch Container Insights and add tags
  6. Click “Create”

AWS Cluster Create

2. Create Task Definition

AWS Create Task Definition

  1. In the ECS dashboard, go to “Task Definitions” and click “Create new Task Definition”
  2. Set Task Definition Name (e.g., gorules-brms-task)
  3. Select "Fargate" as the launch type compatibility
  4. Under architecture, choose Linux X86_64
  5. Set Task memory and CPU (for dev environment 0.5CPU and 1GB RAM is enough)
  6. Click "Add container" and configure:
    1. Container name (e.g., gorules-container)
    2. Image URI (from your ECR repository or other registry)
    3. Port mappings (Port 80)
    4. Environment variables (including database connection string, using the password from Aurora setup)
  7. Add any additional containers if required (e.g., for logging or monitoring)
  8. Click "Add" to add the container to the task definition
  9. Review and click "Create" to create the task definition

AWS Cluster Create

3. Create ECS Service

AWS Service Create

  1. Go to your ECS Cluster
  2. Click "Create" under the Services tab
  3. Configure the service:
    • Capacity provider: FARGATE
    • Task Definition: Select the task definition you created
    • Service name (e.g., gorules-service)
    • Number of tasks: Set based on your requirements
  4. Configure networking if required
  5. Configure load balancing (Application Load Balancer)
  6. Set Auto Scaling if needed (optional):
    • You can configure service auto scaling based on CPU utilization or other metrics
  7. Review and click "Create Service"

AWS Service Details 1

AWS Service Details 2

img.png

img.png

Next steps

  • Monitor your ECS service in the AWS Console to ensure tasks are running correctly
  • Set up CloudWatch logs to monitor application logs
  • Configure alarms for your ECS service to be notified of any issues

Remember to secure all sensitive information like database credentials using AWS Secrets Manager or environment variables, and never hard-code them in your task definitions or application code.

Notes

  • To make your service accessible, you need to edit service group and allow inbound traffic from all IPv4 (or configure appropriately)
  • To obtain DB_SSL_CA go to AWS Docs find certificate for your region and use our online tool to convert certificate to base64