-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlambda_function.py
More file actions
48 lines (41 loc) · 1.5 KB
/
Copy pathlambda_function.py
File metadata and controls
48 lines (41 loc) · 1.5 KB
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
import boto3
import os
eks = boto3.client('eks')
def handler(event, context):
action = event.get('action') # 'down' (종료) 또는 'up' (기동)
cluster_name = os.environ['CLUSTER_NAME']
# EKS 클러스터 내부의 노드 그룹 목록을 조회하여 'initial'로 시작하는 노드 그룹 탐색
nodegroups_resp = eks.list_nodegroups(clusterName=cluster_name)
nodegroups = nodegroups_resp.get('nodegroups', [])
nodegroup_name = None
for ng in nodegroups:
if ng.startswith('initial'):
nodegroup_name = ng
break
if not nodegroup_name:
if nodegroups:
nodegroup_name = nodegroups[0]
else:
raise Exception(f"No nodegroups found in cluster {cluster_name}")
if action == 'down':
min_size = 0
max_size = 1 # EKS 제약: max_size는 1 이상이어야 함
desired_size = 0
else:
min_size = 1
max_size = 3
desired_size = 2
print(f"Updating nodegroup {nodegroup_name} config: min={min_size}, max={max_size}, desired={desired_size}")
response = eks.update_nodegroup_config(
clusterName=cluster_name,
nodegroupName=nodegroup_name,
scalingConfig={
'minSize': min_size,
'maxSize': max_size,
'desiredSize': desired_size
}
)
return {
'statusCode': 200,
'body': f"EKS nodegroup {nodegroup_name} config update initiated successfully."
}