Monitoring memory usage in AWS CloudWatch for Windows instance

First, you need to add an IAM role to your instance:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowAccessToSSM",
            "Effect": "Allow",
            "Action": [
                "cloudwatch:PutMetricData",
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:DescribeLogGroups",
                "logs:DescribeLogStreams",
                "logs:PutLogEvents"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}

Note that you cannot add a role to an existing instance. So do it before launching. Then you need to configure the EC2Config file (normally) accessible via the following path:

C:\Program Files\Amazon\Ec2ConfigService\Settings.AWS.EC2.Windows.CloudWatch.json

You should add the following block to the JSON file:

...

{
    "Id": "PerformanceCounter",
    "FullName": "AWS.EC2.Windows.CloudWatch.PerformanceCounterComponent.PerformanceCounterInputComponent,AWS.EC2.Windows.CloudWatch",
    "Parameters": {
        "CategoryName": "Memory",
        "CounterName": "Available MBytes",
        "InstanceName": "",
        "MetricName": "Memory",
        "Unit": "Megabytes",
        "DimensionName": "InstanceId",
        "DimensionValue": "{instance_id}"
    }
}

...

{
    "Id": "CloudWatch",
    "FullName": "AWS.EC2.Windows.CloudWatch.CloudWatch.CloudWatchOutputComponent,AWS.EC2.Windows.CloudWatch",
    "Parameters": 
    {
        "AccessKey": "",
        "SecretKey": "",
        "Region": "eu-west-1",
        "NameSpace": "PerformanceMonitor"
    }
}

Do not forget to restart the EC2Config service on your server after changing the config file. You should be able to get the memory metrics after a couple of minutes in your CloudWatch console. The level of CloudWatch monitoring on your instance should also be set to detailed:

enter image description here

Update:

According to the documentation, you can now attach or modify an IAM role to your existing instance.


I am running a Windows 2012 Base R2 Server and it is running EC2Config Version greater than 4.0. If anyone faces the same problem, please restart the Amazon SSM Agent Service after restarting EC2Config Service.

I read it in the following link [STEP-6] :

http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/send_logs_to_cwl.html

It reads the following :

If you are running EC2Config version 4.0 or later, then you must restart the SSM Agent on the instance from the Microsoft Services snap-in.

I solved my issue by doing this.