|
1 | 1 | import { ENV } from '../env'
|
2 | 2 |
|
3 |
| -const webEcsOption: EcsOption = { |
4 |
| - desiredCount: ENV.isProduction ? 2 : 1, |
5 |
| - containerCpu: ENV.isProduction ? 1024 : 512, |
6 |
| - containerMemory: ENV.isProduction ? 2048 : 1024, |
| 3 | +// fargate cpu memory combination |
| 4 | +// See: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html |
| 5 | +// 0.25 vCPU : 0.5 GB ~ 2 GB |
| 6 | +// 0.5 vCPU : 1 GB ~ 4 GB |
| 7 | +// 1 vCPU : 2 GB ~ 8 GB |
| 8 | +// 2 vCPU : 4 GB ~ 16 GB |
| 9 | +// 4 vCPU : 8 GB ~ 30 GB |
| 10 | + |
| 11 | +const webProdEcsOption: EcsBaseOption = { |
| 12 | + desiredCount: 2, |
| 13 | + cpu: 1, // unit 1024 |
| 14 | + memory: 2, // unit 1024 |
| 15 | + maxCapacity: 12, |
| 16 | + minCapacity: 2, |
| 17 | +} |
| 18 | + |
| 19 | +const webStageEcsOption: EcsBaseOption = { |
| 20 | + desiredCount: 1, |
| 21 | + cpu: 0.5, // unit 1024 |
| 22 | + memory: 1, // unit 1024 |
7 | 23 | maxCapacity: 12,
|
8 |
| - minCapacity: ENV.isProduction ? 2 : 1, |
| 24 | + minCapacity: 1, |
9 | 25 | }
|
10 | 26 |
|
11 |
| -const serverEcsOption: EcsOption = { |
12 |
| - desiredCount: ENV.isProduction ? 2 : 1, |
13 |
| - containerCpu: ENV.isProduction ? 1024 : 512, |
14 |
| - containerMemory: 1024, |
| 27 | +const serverProdEcsOption: EcsBaseOption = { |
| 28 | + desiredCount: 2, |
| 29 | + cpu: 0.5, // unit 1024 |
| 30 | + memory: 1, // unit 1024 |
15 | 31 | maxCapacity: 12,
|
16 |
| - minCapacity: ENV.isProduction ? 2 : 1, |
| 32 | + minCapacity: 2, |
17 | 33 | }
|
18 | 34 |
|
19 |
| -const cronEcsOption: EcsOption = { |
20 |
| - desiredCount: ENV.isProduction ? 1 : 0, |
21 |
| - containerCpu: ENV.isProduction ? 1024 : 512, |
22 |
| - containerMemory: 1024, |
| 35 | +const serverStageEcsOption: EcsBaseOption = { |
| 36 | + desiredCount: 1, |
| 37 | + cpu: 0.25, // unit 1024 |
| 38 | + memory: 1, // unit 1024 |
| 39 | + maxCapacity: 12, |
| 40 | + minCapacity: 1, |
| 41 | +} |
| 42 | + |
| 43 | +const cronProdEcsOption: EcsBaseOption = { |
| 44 | + desiredCount: 1, |
| 45 | + cpu: 1, // unit 1024 |
| 46 | + memory: 2, // unit 1024 |
23 | 47 | maxCapacity: 1,
|
24 |
| - minCapacity: ENV.isProduction ? 1 : 0, |
| 48 | + minCapacity: 1, |
| 49 | +} |
| 50 | + |
| 51 | +const cronStageEcsOption: EcsBaseOption = { |
| 52 | + desiredCount: 0, |
| 53 | + cpu: 0.25, // unit 1024 |
| 54 | + memory: 0.5, // unit 1024 |
| 55 | + maxCapacity: 0, |
| 56 | + minCapacity: 0, |
25 | 57 | }
|
26 | 58 |
|
27 | 59 | export const ecsOption = {
|
28 |
| - web: webEcsOption, |
29 |
| - server: serverEcsOption, |
30 |
| - cron: cronEcsOption, |
| 60 | + web: generateEcsOption(ENV.isProduction ? webProdEcsOption : webStageEcsOption), |
| 61 | + server: generateEcsOption(ENV.isProduction ? serverProdEcsOption : serverStageEcsOption), |
| 62 | + cron: generateEcsOption(ENV.isProduction ? cronProdEcsOption : cronStageEcsOption), |
| 63 | +} |
| 64 | + |
| 65 | +function generateEcsOption(option: EcsBaseOption): EcsOption { |
| 66 | + return { |
| 67 | + desiredCount: option.desiredCount, |
| 68 | + taskCpu: `${option.cpu} vCPU`, |
| 69 | + taskMemory: `${option.memory} GB`, |
| 70 | + containerCpu: 1024 * option.cpu, |
| 71 | + containerMemory: 1024 * option.memory, |
| 72 | + maxCapacity: option.maxCapacity, |
| 73 | + minCapacity: option.minCapacity, |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +type EcsBaseOption = { |
| 78 | + desiredCount: number |
| 79 | + cpu: number |
| 80 | + memory: number |
| 81 | + maxCapacity: number |
| 82 | + minCapacity: number |
31 | 83 | }
|
32 | 84 |
|
33 | 85 | type EcsOption = {
|
34 | 86 | desiredCount: number
|
| 87 | + taskCpu: string |
| 88 | + taskMemory: string |
35 | 89 | containerCpu: number
|
36 | 90 | containerMemory: number
|
37 | 91 | maxCapacity: number
|
|
0 commit comments