Create ECS Task Definition for Project database
Create database task definition for ECS Faregate.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
########################################################
# Pull parameters from aws and store oders. #
# in order to get IP address, username and password #
# for the database running in the Fargate container #
# ENV, AZ, DB_USERNAME and DB_PASSWORD are impoted #
# from the pipeline. #
########################################################
# Import variables from GitHub Secrets
ENV="$1"
AZ="$2"
DB_USERNAME="$3"
DB_PASSWORD="$4"
# Get parameters from AWS Parameter Store
LOGS="$(aws ssm get-parameter --name "$ENV.LogGroup.App" --query "Parameter.Value" --output text)"
EFS="$(aws ssm get-parameter --name "$ENV.AppSystemFiles.App" --query "Parameter.Value" --output text)"
TASKROLE="$(aws ssm get-parameter --name "$ENV.EcsDBTaskRole.App" --query "Parameter.Value" --output text)"
TASKEXROLE="$(aws ssm get-parameter --name "$ENV.EcsTaskExecutionRole.App" --query "Parameter.Value" --output text)"
# Create parameters for database
aws ssm put-parameter --name "$ENV.DataBase.DB_PASSWORD.App" --type "String" --value "$DB_PASSWORD" --overwrite
aws ssm put-parameter --name "$ENV.DataBase.DB_USERNAME.App" --type "String" --value "$DB_USERNAME" --overwrite
# Create new task definition for DataBase
cat <<EOF >> ./infrastructure/ecs/db-task.json
{
"containerDefinitions": [
{
"name": "mysql",
"image": "mysql:8.0",
"essential": true,
"memory": 2048,
"linuxParameters": {
"initProcessEnabled": true
},
"environment": [
{
"name": "MYSQL_USER",
"value": "$DB_USERNAME"
},
{
"name": "MYSQL_PASSWORD",
"value": "$DB_PASSWORD"
},
{
"name": "MYSQL_DATABASE",
"value": "$DB_USERNAME"
},
{
"name": "MYSQL_ROOT_PASSWORD",
"value": "$DB_PASSWORD"
}
],
"mountPoints": [
{
"sourceVolume": "efs-db",
"containerPath": "/var/lib/mysql"
}
],
"portMappings": [
{
"containerPort": 3306,
"hostPort": 3306
}
],
"healthCheck": {
"command": ["CMD", "mysqladmin", "ping", "-p$DB_PASSWORD"],
"interval": 5,
"timeout": 3,
"startPeriod": 10,
"retries": 3
},
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "$LOGS",
"awslogs-region": "$AZ",
"awslogs-stream-prefix": "ecs-db"
}
}
}
],
"volumes": [
{
"name": "efs-db",
"efsVolumeConfiguration": {
"fileSystemId": "$EFS"
}
}
],
"family": "DataBase-CSI-TaskDefinition",
"cpu": "1024",
"memory": "2048",
"networkMode": "awsvpc",
"taskRoleArn": "$TASKROLE",
"executionRoleArn": "$TASKEXROLE",
"runtimePlatform": {
"operatingSystemFamily": "LINUX"
},
"requiresCompatibilities": ["FARGATE"]
}
EOF
This post is licensed under CC BY 4.0 by the author.
Comments powered by Disqus.