Skip to content

Commit 84b7118

Browse files
committed
Handle EC2 instances without tags
1 parent d146460 commit 84b7118

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

cost_watcher/lambda_function.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"c5a.2xlarge",
3131
"c6g.medium",
3232
"c5.2xlarge",
33+
"m7i-flex.large",
3334
]
3435
no_launch_policy_arn = "arn:aws:iam::492475357299:policy/EC2AccessNoRunInstances"
3536

@@ -121,7 +122,9 @@ def get_active_ec2_instances() -> Dict[str, Dict[str, Union[datetime.datetime, s
121122
for instance in ec2_iter:
122123
launch_time = instance.launch_time.astimezone(tz=datetime.timezone.utc)
123124
duration = current_time - launch_time
124-
tags = {x["Key"]: x["Value"] for x in instance.tags}
125+
tags = (
126+
{x["Key"]: x["Value"] for x in instance.tags} if instance.tags else dict()
127+
)
125128
if "Name" in tags:
126129
# Exclude the Dashboard website
127130
if tags["Name"] in ["XGBoost CI Dashboard"]:

0 commit comments

Comments
 (0)