This simple Lambda JS code can be used to update CPU Credits to 'unlimited' for a newly launched instances.
We had configured Auto-scaling. Due to budget constraint all the instances were on most basic spec possible (t2.micro or t2.nano) To avoid outage, we had enabeld T2 Unlimited on all. Since, autoscaling creates new instance, this may lead to outage.
Under CloudWatch events, create an event source with following configuration -
{
"source": [
"aws.autoscaling"
],
"detail-type": [
"EC2 Instance Launch Successful"
]
}
Invoke this Lamdba as Target. You're good to go.
The permission required for execution are under iam_policy.json
(apart from Lambda Basic Execution)