CloudWatch agent setup: IAM permissions and VPC endpoints
The CloudWatch User Guide lists two prerequisites. The agent needs an IAM role (on EC2) or an IAM user (on premises) with CloudWatchAgentServerPolicy, and it needs HTTPS access to the CloudWatch and CloudWatch Logs endpoints through an internet gateway, a NAT gateway, interface VPC endpoints or a proxy. A Parameter Store configuration must be named with the AmazonCloudWatch- prefix.
Which permissions does the agent need?
Attach CloudWatchAgentServerPolicy to the role or user on every server that runs the agent. It lets the agent publish metrics, create and write log groups and streams, and read its configuration from Parameter Store. Missing permissions often show as an agent that starts but publishes nothing.
The policy grants ssm:GetParameter only on parameters whose names begin with AmazonCloudWatch-. A configuration stored under any other name fails with AccessDeniedException on GetParameter. An AccessDeniedException on PutMetricData or PutLogEvents means the policy is not attached to the instance role.
Saving a configuration to Parameter Store is a different permission. AWS has you do it from an EC2 instance that has the CloudWatchAgentAdminRole role attached.
How does the agent get credentials on premises?
An on-premises server has no instance role, so you create an IAM user with the same policy and give the agent that user's access key and secret key, together with the Region to send data to.
The keys go in a credentials profile. If the profile is named AmazonCloudWatchAgent, nothing more is needed. A different profile name has to be specified in the agent's configuration.
How does the agent reach CloudWatch from a private subnet?
The agent sends data over HTTPS on port 443 to monitoring.region.amazonaws.com for metrics and logs.region.amazonaws.com for logs. It also calls ec2.region.amazonaws.com to look up instance tags.
In a private subnet with no NAT gateway, create an interface VPC endpoint for each service and enable private DNS on it. The CloudWatch endpoint is com.amazonaws.region.monitoring and the CloudWatch Logs endpoint is com.amazonaws.region.logs. If Systems Manager installs the agent or Parameter Store holds its configuration, add endpoints for ssm, ssmmessages and ec2messages. Amazon S3 uses a gateway endpoint.
Which metrics come only from the agent?
The agent publishes to the CWAgent namespace by default. Its Linux metrics include disk_used_percent, the percentage of total disk space used, and mem_used_percent, the percentage of memory in use.
Where the exam catches people
Storing the agent configuration under a custom parameter path: CloudWatchAgentServerPolicy reads only parameters that begin with AmazonCloudWatch-.
Creating only a CloudWatch endpoint in a private subnet: metrics use monitoring and log events use logs, so each needs its own interface endpoint.
Looking for an instance role on an on-premises server: the agent there uses an IAM user's access keys in the AmazonCloudWatchAgent profile.
Looking for disk-space or memory metrics in the AWS/EC2 namespace: disk_used_percent and mem_used_percent are agent metrics in CWAgent.
Creating an interface endpoint for Amazon S3 to download the agent package: AWS says to create a gateway endpoint for S3.