@@ -14,11 +14,37 @@ export interface LinuxParametersProps {
14
14
readonly initProcessEnabled ?: boolean ;
15
15
16
16
/**
17
- * The value for the size (in MiB) of the /dev/shm volume.
17
+ * The value for the size of the /dev/shm volume.
18
18
*
19
19
* @default No shared memory.
20
20
*/
21
21
readonly sharedMemorySize ?: number ;
22
+
23
+ /**
24
+ * The total amount of swap memory a container can use. This parameter
25
+ * will be translated to the --memory-swap option to docker run.
26
+ *
27
+ * This parameter is only supported when you are using the EC2 launch type.
28
+ * Accepted values are positive integers.
29
+ *
30
+ * @default No swap.
31
+ */
32
+ readonly maxSwap ?: cdk . Size ;
33
+
34
+ /**
35
+ * This allows you to tune a container's memory swappiness behavior. This parameter
36
+ * maps to the --memory-swappiness option to docker run. The swappiness relates
37
+ * to the kernel's tendency to swap memory. A value of 0 will cause swapping to
38
+ * not happen unless absolutely necessary. A value of 100 will cause pages to
39
+ * be swapped very aggressively.
40
+ *
41
+ * This parameter is only supported when you are using the EC2 launch type.
42
+ * Accepted values are whole numbers between 0 and 100. If a value is not
43
+ * specified for maxSwap then this parameter is ignored.
44
+ *
45
+ * @default 60
46
+ */
47
+ readonly swappiness ?: number ;
22
48
}
23
49
24
50
/**
@@ -31,10 +57,20 @@ export class LinuxParameters extends Construct {
31
57
private readonly initProcessEnabled ?: boolean ;
32
58
33
59
/**
34
- * The shared memory size. Not valid for Fargate launch type
60
+ * The shared memory size (in MiB) . Not valid for Fargate launch type
35
61
*/
36
62
private readonly sharedMemorySize ?: number ;
37
63
64
+ /**
65
+ * The max swap memory
66
+ */
67
+ private readonly maxSwap ?: cdk . Size ;
68
+
69
+ /**
70
+ * The swappiness behavior
71
+ */
72
+ private readonly swappiness ?: number ;
73
+
38
74
/**
39
75
* Capabilities to be added
40
76
*/
@@ -61,8 +97,30 @@ export class LinuxParameters extends Construct {
61
97
constructor ( scope : Construct , id : string , props : LinuxParametersProps = { } ) {
62
98
super ( scope , id ) ;
63
99
100
+ this . validateProps ( props ) ;
101
+
64
102
this . sharedMemorySize = props . sharedMemorySize ;
65
103
this . initProcessEnabled = props . initProcessEnabled ;
104
+ this . maxSwap = props . maxSwap ;
105
+ this . swappiness = props . maxSwap ? props . swappiness : undefined ;
106
+ }
107
+
108
+ private validateProps ( props : LinuxParametersProps ) {
109
+ if (
110
+ ! cdk . Token . isUnresolved ( props . sharedMemorySize ) &&
111
+ props . sharedMemorySize !== undefined &&
112
+ ( ! Number . isInteger ( props . sharedMemorySize ) || props . sharedMemorySize < 0 )
113
+ ) {
114
+ throw new Error ( `sharedMemorySize: Must be an integer greater than 0; received ${ props . sharedMemorySize } .` ) ;
115
+ }
116
+
117
+ if (
118
+ ! cdk . Token . isUnresolved ( props . swappiness ) &&
119
+ props . swappiness !== undefined &&
120
+ ( ! Number . isInteger ( props . swappiness ) || props . swappiness < 0 || props . swappiness > 100 )
121
+ ) {
122
+ throw new Error ( `swappiness: Must be an integer between 0 and 100; received ${ props . swappiness } .` ) ;
123
+ }
66
124
}
67
125
68
126
/**
@@ -106,6 +164,8 @@ export class LinuxParameters extends Construct {
106
164
return {
107
165
initProcessEnabled : this . initProcessEnabled ,
108
166
sharedMemorySize : this . sharedMemorySize ,
167
+ maxSwap : this . maxSwap ?. toMebibytes ( ) ,
168
+ swappiness : this . swappiness ,
109
169
capabilities : {
110
170
add : cdk . Lazy . list ( { produce : ( ) => this . capAdd } , { omitEmpty : true } ) ,
111
171
drop : cdk . Lazy . list ( { produce : ( ) => this . capDrop } , { omitEmpty : true } ) ,
0 commit comments