Skip to content

Commit f6d1b0d

Browse files
authored
Merge pull request #119 from caktus/support-custom-eks-nodegroup-ami-images
Support Custom EKS Nodegroup AMI Images
2 parents 6eabb66 + d4e90c4 commit f6d1b0d

File tree

4 files changed

+99
-5
lines changed

4 files changed

+99
-5
lines changed

.github/workflows/pre-commit.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ jobs:
99
pre-commit:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v2
13-
- uses: actions/setup-python@v2
14-
- uses: pre-commit/action@v2.0.0
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-python@v3
14+
- uses: pre-commit/action@v3.0.1

CHANGELOG.rst

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,41 @@
11
Change Log
22
==========
33

4-
`X.Y.Z`_ (TBD-DD-DD)
4+
`2.4.0`_ (2025-09-08)
5+
---------------------
6+
7+
**Backwards-incompatible changes:**
8+
9+
* EBS volume type for worker nodes has been changed from ``gp2`` to ``gp3``. This will result in node replacement. Workload migration should still be managed by AWS.
10+
11+
**What's new in 2.4.0 (#119):**
12+
13+
* **Custom AMI Support**:
14+
15+
* Added support for conditionally specifying custom AMIs for EKS node groups.
16+
* New parameters:
17+
18+
- ``CustomAMIImageType``: Corresponding image type (e.g., ``AL2023_x86_64_STANDARD``, ``AL2_x86_64``).
19+
- ``CustomEKSAMI``: AMI ID to use for worker nodes. If ``CustomAMIImageType`` is set, one isn't required to set ``CustomEKSAMI``.
20+
21+
* Conditional logic ensures that these settings are only applied when explicitly provided.
22+
23+
* **Cluster Version Parameterization**:
24+
25+
* Introduced ``EksClusterVersion`` parameter to allow template users to control the Kubernetes version.
26+
* If this parameter is not set, AWS will default to the version already in place.
27+
28+
* **Launch Template Enhancements**:
29+
30+
* Node group now uses a versioned launch template reference. This will support inplace changes rather than entire nodegroup replacement where possible.
31+
* Custom AMI ID is injected into the launch template conditionally, based on user input.
32+
33+
* **EBS Improvements**:
34+
35+
* Changed block storage type from ``gp2`` to ``gp3`` in the launch template for better performance and cost optimization.
36+
37+
38+
`2.3.0`_ (2024-11-21)
539
---------------------
640

741

@@ -234,6 +268,8 @@ Backwards-incompatible changes:
234268
* Initial public release
235269

236270

271+
.. _2.4.0: https://aws-web-stacks.s3.amazonaws.com/index.html?prefix=2.4.0/
272+
.. _2.3.0: https://aws-web-stacks.s3.amazonaws.com/index.html?prefix=2.3.0/
237273
.. _2.2.0: https://aws-web-stacks.s3.amazonaws.com/index.html?prefix=2.2.0/
238274
.. _2.1.2: https://aws-web-stacks.s3.amazonaws.com/index.html?prefix=2.1.2/
239275
.. _2.1.1: https://aws-web-stacks.s3.amazonaws.com/index.html?prefix=2.1.1/

stack/database.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@
199199
"postgres12",
200200
"postgres13",
201201
"postgres14",
202+
"postgres15",
203+
"postgres16",
204+
"postgres17",
202205
"sqlserver-ee-11.0",
203206
"sqlserver-ee-12.0",
204207
"sqlserver-ee-13.0",

stack/eks.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,62 @@
105105
label="Cluster name",
106106
))
107107

108+
custom_eks_ami = Ref(template.add_parameter(
109+
Parameter(
110+
"CustomEKSAMI",
111+
Description="Custom AMI ID for the EKS node group. It is recommended not to set this value, as AWS will automatically select the most optimized image when CustomAMIImageType is specified.", # noqa
112+
Type="String",
113+
Default="",
114+
),
115+
group="Elastic Kubernetes Service (EKS)",
116+
label="Custom EKS AMI",
117+
))
118+
119+
use_custom_ami = "UseCustomAMI"
120+
template.add_condition(
121+
use_custom_ami,
122+
Not(Equals(custom_eks_ami, ""))
123+
)
124+
125+
custom_ami_image_type = Ref(template.add_parameter(
126+
Parameter(
127+
"CustomAMIImageType",
128+
Description="The image type to match the custom AMI. E.g., AL2023_x86_64_STANDARD, AL2_x86_64",
129+
Type="String",
130+
Default="",
131+
),
132+
group="Elastic Kubernetes Service (EKS)",
133+
label="Custom AMI Image Type",
134+
))
135+
136+
use_custom_ami_type = "UseCustomAMIType"
137+
template.add_condition(
138+
use_custom_ami_type,
139+
Not(Equals(custom_ami_image_type, ""))
140+
)
141+
142+
cluster_version = Ref(template.add_parameter(
143+
Parameter(
144+
"EksClusterVersion",
145+
Description="The version of Kubernetes to use for the EKS cluster",
146+
Type="String",
147+
Default="",
148+
),
149+
group="Elastic Kubernetes Service (EKS)",
150+
label="Kubernetes Cluster Version",
151+
))
152+
153+
use_cluster_version = "UseEksClusterVersion"
154+
template.add_condition(
155+
use_cluster_version,
156+
Not(Equals(cluster_version, ""))
157+
)
158+
108159
cluster = eks.Cluster(
109160
"EksCluster",
110161
template=template,
111162
Name=cluster_name,
163+
Version=If(use_cluster_version, cluster_version, Ref("AWS::NoValue")),
112164
Logging=eks.Logging(
113165
ClusterLogging=eks.ClusterLogging(
114166
EnabledTypes=[
@@ -145,14 +197,15 @@
145197
"NodegroupLaunchTemplate",
146198
template=template,
147199
LaunchTemplateData=ec2.LaunchTemplateData(
200+
ImageId=If(use_custom_ami, custom_eks_ami, Ref("AWS::NoValue")),
148201
BlockDeviceMappings=[
149202
ec2.LaunchTemplateBlockDeviceMapping(
150203
DeviceName="/dev/xvda",
151204
Ebs=ec2.EBSBlockDevice(
152205
DeleteOnTermination=True,
153206
Encrypted=use_aes256_encryption,
154207
KmsKeyId=If(use_cmk_arn, Ref(cmk_arn), Ref("AWS::NoValue")),
155-
VolumeType="gp2",
208+
VolumeType="gp3",
156209
VolumeSize=container_volume_size,
157210
),
158211
),
@@ -179,6 +232,7 @@
179232
NodeRole=GetAtt(container_instance_role, "Arn"),
180233
LaunchTemplate=eks.LaunchTemplateSpecification(
181234
Id=Ref(nodegroup_launch_template),
235+
Version=GetAtt(nodegroup_launch_template, "LatestVersionNumber"),
182236
),
183237
# The rest are optional.
184238
ScalingConfig=eks.ScalingConfig(
@@ -187,6 +241,7 @@
187241
MinSize=2,
188242
),
189243
Subnets=[Ref(private_subnet_a), Ref(private_subnet_b)],
244+
AmiType=If(use_custom_ami_type, custom_ami_image_type, Ref("AWS::NoValue"))
190245
)
191246

192247
# OUTPUTS

0 commit comments

Comments
 (0)