I want to allow a script running on my EC2 instance to indicate when it is healthy to the autoscaling group. To do so, I can run the following from my script:
aws --region $AWSREGION \
autoscaling \
set-instance-health \
--instance-id $(curl http://169.254.169.254/latest/meta-data/instance-id) \
--health-status Unhealthy
Before granting any special permissions to the IAM role, I get the following error (as I'd expect):
An error occurred (AccessDenied) when calling the SetInstanceHealth operation: User: arn:aws:sts::ACCOUNTID:assumed-role/ROLENAME/i-INSTANCEID is not authorized to perform: autoscaling:SetInstanceHealth
I could add the following statement to my IAM role to get around this:
{
"Action": [
"autoscaling:SetInstanceHealth"
],
"Effect": "Allow",
"Resource": "*"
}
But wouldn't that allow instances in this role to set instance health on all instances (assuming they know the instance id)? I wouldn't want one compromised instance being able to take others out of their own ASGs.