ECS Multi-Container Deployment - EC2 Launch Type
This guide provides instructions for deploying a multi-container application on ECS using EC2 instances. It covers creating task definitions, setting up services, and configuring a load balancer for communication between containers. The deployment ensures proper routing and health checks for each service.
Step 1: Create an ECS EC2 Cluster
Create an ECS EC2 cluster in Amazon ECS to deploy the application within the services. You can create the cluster using this link. Once the cluster is created, it will look similar to the image below in the cluster home page.
Step 2: Create Task Definitions
Create task definitions for each deployment and configure the services to deploy the respective task definitions.
-
To create a task definition, click the Create new task definition with JSON option, copy the task definition provided below for each service, paste it in the task definition creation window, and click Create.
- Create multiple task definitions for each container .
- The task definition is provided in JSON format.
IDP Web Task definition
{
"family": "id-web-task",
"containerDefinitions": [
{
"name": "id_web_container",
"image": "us-docker.pkg.dev/boldreports/v6-3-24/bold-identity:6.3.24",
"cpu": 1024,
"portMappings": [
{
"name": "id_web_container-80-tcp",
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp"
}
],
"essential": true,
"environment": [
{
"name": "APP_BASE_URL",
"value": "<app_base_url>"
},
{
"name": "INSTALL_OPTIONAL_LIBS", //Set this environment variable if optional libraries need to be installed.
"value": "mysql,oracle,postgresql,snowflake,googlebigquery"
}
],
"mountPoints": [
{
"sourceVolume": "boldreports-EFS",
"containerPath": "/application/app_data",
"readOnly": false
}
],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/boldreports",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "boldreports"
}
},
"systemControls": []
}
],
"taskRoleArn": "arn:aws:iam::142887710098:role/ECS39713role", //Add your task role
"executionRoleArn": "arn:aws:iam::142887710098:role/ecsTaskExecutionRole", //Add your execution role
"networkMode": "bridge",
"volumes": [
{
"name": "boldreports-EFS",
"efsVolumeConfiguration": {
"fileSystemId": "<file-system-id>",
"rootDirectory": "/"
}
}
],
"placementConstraints": [],
"requiresCompatibilities": [
"EC2"
],
"cpu": "2048",
"memory": "4096",
"enableFaultInjection": false
}
IDP API Task definition
{
"family": "id-api-task",
"containerDefinitions": [
{
"name": "id_api_container",
"image": "us-docker.pkg.dev/boldreports/v6-3-24/bold-idp-api:6.3.24",
"cpu": 1024,
"portMappings": [
{
"name": "id_api_container-80-tcp",
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp"
}
],
"essential": true,
"environment": [],
"mountPoints": [
{
"sourceVolume": "boldreports-EFS",
"containerPath": "/application/app_data",
"readOnly": false
}
],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/boldreports",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "boldreports"
},
"secretOptions": []
},
"systemControls": []
}
],
"taskRoleArn": "arn:aws:iam::142887710098:role/ECS39713role", //Add your task role
"executionRoleArn": "arn:aws:iam::142887710098:role/ecsTaskExecutionRole", //Add your execution role
"networkMode": "bridge",
"volumes": [
{
"name": "boldreports-EFS",
"efsVolumeConfiguration": {
"fileSystemId": "<file-system-id>",
"rootDirectory": "/"
}
}
],
"placementConstraints": [],
"requiresCompatibilities": [
"EC2"
],
"cpu": "2048",
"memory": "4096",
"enableFaultInjection": false
}
IDP UMS Task defintion
{
"family": "id-ums-task",
"containerDefinitions": [
{
"name": "id_ums_container",
"image": "us-docker.pkg.dev/boldreports/v6-3-24/bold-ums:6.3.24",
"cpu": 1024,
"portMappings": [
{
"name": "cont3",
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"environment": [],
"mountPoints": [
{
"sourceVolume": "boldreports-EFS",
"containerPath": "/application/app_data",
"readOnly": false
}
],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/boldreports",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "boldreports"
},
"secretOptions": []
},
"systemControls": []
}
],
"taskRoleArn": "arn:aws:iam::142887710098:role/ECS39713role", //Add your task role
"executionRoleArn": "arn:aws:iam::142887710098:role/ecsTaskExecutionRole", //Add your execution role
"networkMode": "bridge",
"volumes": [
{
"name": "boldreports-EFS",
"efsVolumeConfiguration": {
"fileSystemId": "<file-system-id>",
"rootDirectory": "/"
}
}
],
"placementConstraints": [],
"requiresCompatibilities": [
"EC2"
],
"cpu": "2048",
"memory": "4096",
"enableFaultInjection": false
}
Reporting Web definition
{
"family": "reports-web-task",
"containerDefinitions": [
{
"name": "reports_web_container",
"image": "us-docker.pkg.dev/boldreports/v6-3-24/boldreports-server:6.3.24",
"cpu": 1024,
"portMappings": [
{
"name": "cont4",
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"environment": [],
"mountPoints": [
{
"sourceVolume": "boldreports-EFS",
"containerPath": "/application/app_data",
"readOnly": false
}
],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/boldreports",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "boldreports6"
}
},
"systemControls": []
}
],
"taskRoleArn": "arn:aws:iam::142887710098:role/ECS39713role", //Add your task role
"executionRoleArn": "arn:aws:iam::142887710098:role/ecsTaskExecutionRole", //Add your execution role
"networkMode": "bridge",
"volumes": [
{
"name": "boldreports-EFS",
"efsVolumeConfiguration": {
"fileSystemId": "<file-system-id>",
"rootDirectory": "/"
}
}
],
"placementConstraints": [],
"requiresCompatibilities": [
"EC2"
],
"cpu": "2048",
"memory": "4096",
"enableFaultInjection": false
}
Reporting API Task definition
{
"family": "reports-api-task",
"containerDefinitions": [
{
"name": "reports_api_container",
"image": "us-docker.pkg.dev/boldreports/v6-3-24/boldreports-server-api:6.3.24",
"cpu": 1024,
"portMappings": [
{
"name": "cont5",
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"environment": [],
"mountPoints": [
{
"sourceVolume": "boldreports-EFS",
"containerPath": "/application/app_data",
"readOnly": false
}
],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/boldreports",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "boldreports5"
}
},
"systemControls": []
}
],
"taskRoleArn": "arn:aws:iam::142887710098:role/ECS39713role", //Add your task role
"executionRoleArn": "arn:aws:iam::142887710098:role/ecsTaskExecutionRole", //Add your execution role
"networkMode": "bridge",
"volumes": [
{
"name": "boldreports-EFS",
"efsVolumeConfiguration": {
"fileSystemId": "<file-system-id>",
"rootDirectory": "/"
}
}
],
"placementConstraints": [],
"requiresCompatibilities": [
"EC2"
],
"cpu": "2048",
"memory": "4096",
"enableFaultInjection": false
}
Reporting Jobs Task definition
{
"family": "reports-jobs-task",
"containerDefinitions": [
{
"name": "reports_jobs_container",
"image": "us-docker.pkg.dev/boldreports/v6-3-24/boldreports-server-jobs:6.3.24",
"cpu": 1024,
"portMappings": [
{
"name": "cont6",
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"environment": [],
"mountPoints": [
{
"sourceVolume": "boldreports-EFS",
"containerPath": "/application/app_data",
"readOnly": false
}
],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/boldreports",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "boldreports4"
}
},
"systemControls": []
}
],
"taskRoleArn": "arn:aws:iam::142887710098:role/ECS39713role", //Add your task role
"executionRoleArn": "arn:aws:iam::142887710098:role/ecsTaskExecutionRole", //Add your execution role
"networkMode": "bridge",
"volumes": [
{
"name": "boldreports-EFS",
"efsVolumeConfiguration": {
"fileSystemId": "<file-system-id>",
"rootDirectory": "/"
}
}
],
"placementConstraints": [],
"requiresCompatibilities": [
"EC2"
],
"cpu": "2048",
"memory": "4096",
"enableFaultInjection": false
}
Reporting Reportservice Task definition
{
"family": "reports-reportservice-task",
"containerDefinitions": [
{
"name": "reports_reportservice_container",
"image": "us-docker.pkg.dev/boldreports/v6-3-24/boldreports-designer:6.3.24",
"cpu": 1024,
"portMappings": [
{
"name": "cont7",
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"environment": [],
"mountPoints": [
{
"sourceVolume": "boldreports-EFS",
"containerPath": "/application/app_data",
"readOnly": false
}
],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/boldreports",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "boldreports3"
}
},
"systemControls": []
}
],
"taskRoleArn": "arn:aws:iam::142887710098:role/ECS39713role", //Add your task role
"executionRoleArn": "arn:aws:iam::142887710098:role/ecsTaskExecutionRole", //Add your execution role
"networkMode": "bridge",
"volumes": [
{
"name": "boldreports-EFS",
"efsVolumeConfiguration": {
"fileSystemId": "<file-system-id>",
"rootDirectory": "/"
}
}
],
"placementConstraints": [],
"requiresCompatibilities": [
"EC2"
],
"cpu": "2048",
"memory": "4096",
"enableFaultInjection": false
}
Reporting Viewer definition
{
"family": "reports-viewer-task",
"containerDefinitions": [
{
"name": "reports_viewer_container",
"image": "us-docker.pkg.dev/boldreports/v6-3-24/boldreports-viewer:6.3.24",
"cpu": 1024,
"portMappings": [
{
"name": "cont8",
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"environment": [],
"mountPoints": [
{
"sourceVolume": "boldreports-EFS",
"containerPath": "/application/app_data",
"readOnly": false
}
],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/boldreports",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "boldreports2"
}
},
"systemControls": []
}
],
"taskRoleArn": "arn:aws:iam::142887710098:role/ECS39713role", //Add your task role
"executionRoleArn": "arn:aws:iam::142887710098:role/ecsTaskExecutionRole", //Add your execution role
"networkMode": "bridge",
"volumes": [
{
"name": "boldreports-EFS",
"efsVolumeConfiguration": {
"fileSystemId": "<file-system-id>",
"rootDirectory": "/"
}
}
],
"placementConstraints": [],
"requiresCompatibilities": [
"EC2"
],
"cpu": "2048",
"memory": "4096",
"enableFaultInjection": false
}
Reporting ETL definition
{
"family": "reports-etl-task",
"containerDefinitions": [
{
"name": "reports_etl_container",
"image": " us-docker.pkg.dev/boldreports-dev/images/bold-etl:6.3.24_alb_etl",
"cpu": 1024,
"portMappings": [
{
"name": "cont9",
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"environment": [],
"mountPoints": [
{
"sourceVolume": "boldreports-EFS",
"containerPath": "/application/app_data",
"readOnly": false
}
],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/boldreports",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "boldreports1"
}
},
"systemControls": []
}
],
"taskRoleArn": "arn:aws:iam::142887710098:role/ECS39713role", //Add your task role
"executionRoleArn": "arn:aws:iam::142887710098:role/ecsTaskExecutionRole", //Add your execution role
"networkMode": "bridge",
"volumes": [
{
"name": "boldreports-EFS",
"efsVolumeConfiguration": {
"fileSystemId": "<file-system-id>",
"rootDirectory": "/"
}
}
],
"placementConstraints": [],
"requiresCompatibilities": [
"EC2"
],
"cpu": "2048",
"memory": "4096",
"enableFaultInjection": false
}
Step 3: Service Creation
To create a service, please follow the steps below for all task definitions.
-
Go to the created cluster and click Create under the Service tab.
-
Select EC2 as the launch type.
-
Select the task definition to be deployed and provide a name for the service.
-
To connect all the services, create a common load balancer and choose a listener based on your preference (80 or 443).
-
Create a new target group for each service with the respective protocol. Provide the path pattern and evaluation order for each service as shown below.
Services Path Pattern Evaluation Order id-web /* 10 id-ums /ums/* 9 id-api /api/* 8 reporting-web /reporting/* 7 reporting-jobs /reporting/jobs/* 6 reporting-api /reporting/api/* 5 reporting-viewer /reporting/viewer/* 4 etl-service /etlservice/* 3 reporting-designer /reporting/reportservice/* 2 Note: For all services, the health check path should be /health-check, but for the ETL service, it should be /etlservice/health-check.
-
Click Create to create the service.
-
Repeat the steps for each deployment and create the service.
-
Once the targets in the target group reach a healthy state, use the load balancer’s DNS to access the file.
Note:
- Verify the URL in the product.json file and update it as needed. Then, delete all files in the /mount_point/configuration directory except for product.json.
- Documentation for port 80 has been provided; if the load balancer is configured to listen on port 443, please ensure that all incoming requests on port 80 are automatically redirected to port 443.
- Now access the URL and configure the application by following the documentation below :
Application Startup
Please refer to the file below for the latest image: