cloudwatch.put_metric_alarm(
AlarmName='EC2Instance50Percent',
MetricName='Runtime',
Namespace='CustomEC2Metrics',
Threshold=500, # Example threshold: 500 minutes (50% of the budget)
ComparisonOperator='GreaterThanOrEqualToThreshold',
EvaluationPeriods=1,
Period=300,
ActionsEnabled=True,
AlarmActions=[
'arn:aws:sns:region:account-id:DataScienceTeamAlerts' # SNS topic
],
Dimensions=[{'Name': 'InstanceId', 'Value': instance_id}]
)