◷ Reading Time: 17 minutes
FlexRule Server can be run in AWS using Elastic Container Services.

Basic Architecture in AWS

The architecture above shows an ECS cluster running FlexRule Server with one master and one agent node.
Each node is run as a task within an ECS cluster. A task definition with commands and environment variables is created so it can be deployed as a task multiple times. This allows you to add and remove agents to scale your operations.
Traffic Routing
A load balancer routes traffic to the Master API and Workbench based on the port number of the request.
A target group is set up for each port and allows us to point requests to that port to the correct endpoint in the service.
Deployment
Each task is created from a task definition which contains details on how to run the container service and which container image to use.
You will need to choose either the FlexRule Server Windows or Linux container image depending on the type of container you have chosen to provision.
Step-by-Step Instructions
1. Create a Load Balancer
Go to EC2 > Load Balancing > Load Balancers.
Click on Create Load Balancer.

For the Load Balancer type, choose Application Load Balancer.

Give your Load Balancer a name and choose how it can be accessed.

Add some listeners to define which ports you want to route traffic for.
Our example uses ports 9000, 9003, and 9010.

Select your VPC and Availability Zones and click Next.
Click Next on Step 2 since we’re not using secure listeners.
Create a new security group or select an existing one and click Next.
Step 4 requires you to create a target group. This won’t be of much use just yet as we haven’t yet set up the ECS service that this load balancer will point to. Give the target group a name, choose the IP target type, and click Next.
Click Next on Step 5 (Register Targets) as we’ll set this up later.
Click Next on Step 6 (Review).

Once your load balancer has been created it will be given a DNS name. This is the address to set in your configuration settings for FlexRule as all requests will be routed through this load balancer. Copy and paste this somewhere for future reference or you can always come back to it.

In the Listeners tab for your load balancer, delete all listeners.
(We’ll add them back later)
Go to EC2 > Target Groups and delete the target group we just created.
(We’ll create a brand new one later)

2. Create Task Definitions
In this step we will create two task definitions:
- FlexRuleMaster Task Definition
- FlexRuleAgent Task Definition
The steps are identical except for the container command and the configuration settings. Repeat these steps twice to create the two task definitions.
Go to ECS > Task Definitions.

Click on Create New Task Definition.

Choose your Launch Type.
For this tutorial, we will be using Fargate. Please note that at the time of writing this tutorial Fargate only works with Linux containers.

Enter a name for your task definition. Use either FlexRuleMaster or FlexRuleAgent depending on which task definition you are creating.
The options directly under the name are optional. You can leave the defaults as they are if preferred.

In the Container Definitions section click on Add Container.

This will open the Container Definition page where you have to enter details regarding where to get the container image from and specify some parameters similar to a docker run
command if using the CLI with Docker Desktop.
Give your container a name. The user either FlexRuleContainerMaster or FlexRuleContainerAgent depending on the task definition you are creating.
Enter the address for the latest official FlexRule Server container image.

As there are a lot of optional fields on this page, we will only go through the mandatory fields in this tutorial.
Add port mappings:
Port 9000 and 9010 if you’re creating the master.
Port 9003 if you’re creating the agent.
For the agent task definition ONLY: Add the following to the Command field.
This tells the task definition that we’re running an agent and not a master. -runagent,-container

Add environment variables so FlexRule Server can use these in its required configuration settings. These are different for master and agent.
Environment Variables for Master Task
Database details for connecting to the FlexRule Server database.
Master_DB_Server | Server address to your Azure SQL database. |
Master_DB_Name | Name of your database on the server. |
Master_DB_User | Username which has access to the database. |
Master_DB_Password | Password for the username specified. |
URLs for communication between FlexRule Server components.
Master_ApiAddress | Load Balance DNS name label with the port number 9000 . |
Master_WorkbenchAuth | Load Balance DNS name label with the port number 9000 . |
Master_WorkbenchAddress | Load Balance DNS name label with the port number 9010 . |
Keys used for licensing, communication, and encryption.
AuthSigningKey | Get this configuration value from your Windows Installation configuration file. |
MasterAgentSharedSecret | Get this configuration value from your Windows Installation configuration file. |
MasterEncryptionPassword | Get this configuration value from your Windows Installation configuration file. |
License | Obtain a FlexRule Server license key file and copy-paste its value here. |
Static values – copy and paste these in as environment variables.
LogFolder | /frs |
Master_WorkbenchPath | Workbench |
Master_GenericLogger | FlexRule.Server.Logging.LogFileWriter,FlexRule.Server.Library |
Monitoring_Channel | [{type:'ConsoleTraceListener', initialData:'', name:'ConsoleTraceListener'}] |
Monitoring_Event | [{event:'GenericTraceEvent', channel:'ConsoleTraceListener', level:'Verbose', enabled:true},{event:'ExceptionTraceEvent', channel:'ConsoleTraceListener', level:'Error', enabled:true}] |
Environment Variables for Agent Task
Database details for connecting to the FlexRule Server database.
Agent_DB_Server | Server address to your Azure SQL database. |
Agent_DB_Name | Name of your database on the server. |
Agent_DB_User | Username which has access to the database. |
Agent_DB_Password | Password for the username specified. |
URLs for communication between FlexRule Server components.
Agent_ApiAddress | http://*:9003 where 9003 is the port number for this agent. |
Agent_MasterAddress | Address to the Load Balance DNS with the port number. |
Keys are used for licensing, communication, and encryption.
Agent_Runtimes | [{version:'*',license:' Your_Runtime_License_Key'}] |
AuthSigningKey | Get this configuration value from your Windows Installation configuration file. |
License | Obtain a FlexRule Server license key file and copy-paste its value here. |
MasterAgentSharedSecret | Get this configuration value from your Windows Installation configuration file. |
MasterEncryptionPassword | Get this configuration value from your Windows Installation configuration file. |
Static values – copy and paste these in as environment variables.
Agent_GenericLogger | FlexRule.Server.Logging.LogFileWriter,FlexRule.Server.Library |
LogFolder | /frs |
Monitoring_Channel | [{type:'ConsoleTraceListener', initialData:'', name:'ConsoleTraceListener'}] |
Monitoring_Event | [{event:'GenericTraceEvent', channel:'ConsoleTraceListener', level:'Verbose', enabled:true},{event:'ExceptionTraceEvent', channel:'ConsoleTraceListener', level:'Error', enabled:true}] |
Once you’ve added your environment variables, Click on Add at the bottom of the page to add the container definition to your task definition.

This should take you back to the Task Definition creation page. Scroll to the bottom and click Create.

Your task definition will take a moment to be created.
You’ll need to create both the task definitions for master and agent. Once they’re ready you should see them both marked as Active.

3. Create an ECS Cluster
In this step, you’ll need to create an ECS cluster and run tasks using the task definition from the previous step.
Go to ECS > Clusters.
Click on Create Cluster.

Choose the Networking Only template. This allows us to use Fargate.

Give your cluster a name and click Create.

Once your cluster is created it will show in the list of clusters available.
4. Run Tasks
Click on the cluster name.

Click on the Tasks tab.

Click on Run new Task.

Click on Switch to launch type as we’re going to be specifying a launch type instead of a capacity provider strategy.

Choose FARGATE as the Launch Type and the task definition we created for the master. This should be called FlexRuleMaster.
Enable Auto-assign public IP.
Edit security group and set required inbound access:

Complete the rest of the form as per your requirements and click Run Task.

It takes a few minutes for the task to start. Once it’s ready, the last status column should show as RUNNING. Click on the task to see more details.
Run another new task with the same settings, except use FlexRuleAgent as the task definition.
After a few minutes, both tasks should show in the tasks list.
6. Create Target Groups
If you haven’t already, delete any listeners for your load balancer and target groups that were created in step 1.
Now that we have a master task running we can create target groups to connect it to the load balancer.
Go to EC2 > Targets Groups.

Click on Create target group.

Add a target group for:
MasterAPI with port 9000.
Workbench with port 9010.

Click on the Targets tab for each target group and then click on Edit.

Add the private IP address from the task you created for the master node along with the corresponding port number.

Click Register. This will add the targets to the target group.
You should have two target groups at this point.

Go to Master API settings, Health Checks, and click Edit.

Change the Health check path to /api/Healths/Master
.

7. Add Listeners to the Load Balancer
We will now add two listeners to forward traffic to the two target groups we created. Carry out the following steps to add a listener for Master API and a listener for Workbench.
Go to EC2 > Load Balancers.
Choose your load balancer and go to the Listeners tab.

Click on Add listener.
Enter the port for your listener.
Set the default action to forward to the target group for the listener.
MasterAPI uses port 9000.
Workbench uses port 9010.
Click on the check icon.

Click on Save.

You should end up with two listeners pointing to two different target groups.

Now you can navigate to the workbench and try out FlexRule Server by going to the host address for your load balancer with the port:9010.http://{load-balancer-name}-{id}.{region}.elb.amazonaws.com:
9010
8. Register the Agent in the Workbench
Sign in to Workbench.

Go to Administration > Agents.

Click on Add Agent.

Give your agent a name, and description, and enter the Public IP to your agent task with your port number at the end in the Host URL field.http://{Public-IP}:9003
You can get the Public IP for your agent by navigating to ECS > Clusters > {Your Cluster Name} > Tasks > {Your Agent Task}.

Click on Enroll.

You should now have an agent added to your list of agents.
Toggle the Status to ON to enable your agent.
