After installing the Amazon CloudWatch Agent on Windows and starting the service, it repeatedly crashes and restarts.
In the Windows Event Log the following events occur with the crash:
Event ID 7031
Error
The Amazon CloudWatch Agent service terminated unexpectedly. It has done this X times.
And:
Event ID 7039
Warning
A service process other than the one launched by the Service Control Manager connected when starting the Amazon CloudWatch Agent service. The Service Control Manager launched process XXX and process XXX connected instead.
In the amazon-cloudwatch-agent.log
file the last error is:
ec2tagger: Unable to initialize EC2 Instance Tags : +NoCredentialProviders: no valid providers in chain.
This behaviour can occur if you haven't attached an IAM role to the instance that grants it permission to write metrics to CloudWatch as well as communicate with EC2 and Systems Manager.
Creation of the IAM role can be completed as follows:
Having created the IAM role you should then attach it to your EC2 instance, either at launch time or by right clicking the instance in EC2 and selecting Instance Settings > Attach/Replace IAM Role.