Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to enable CloudWatch on a running EC2 instance?

It looks like Amazon has a ready-built IAM role to grant instances CloudWatch write access. ( A more restrictive one could also be created if necessary)

But it appears you cannot attach an IAM role to a running instance.

Am I missing something? Do I really have to re-instantiate my whole fleet to enable CloudWatch? I'm reluctant to save plaintext credentials on each host for security reasons.

like image 266
jorfus Avatar asked Dec 18 '25 12:12

jorfus


1 Answers

I assume you're talking about custom CloudWatch metrics. You don't have to restart any instances to enable them. You can create a group in IAM with the following policy and add a user to this group:

{
"Version": "2012-10-17",
"Statement": [
    {
        "Sid": "****************",
        "Effect": "Allow",
        "Action": [
            "cloudwatch:PutMetricData"
        ],
        "Resource": [
            "*"
        ]
    }
]
}

Then you basically copy this user's credentials to awscred file and add the perl script to cron. Yes, I had to copy credentials to each machine where custom metrics collection is enabled.

like image 74
Sergei Rodionov Avatar answered Dec 21 '25 02:12

Sergei Rodionov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!