Certopolis

AWS Certified CloudOps Engineer – Associate

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.

Written from these sources

Try 3 questions on this

Pick an answer to see why each option is right or wrong.

  1. A SysOps administrator installs the CloudWatch agent on Amazon EC2 instances in a private subnet. The subnet's route table has no route to a NAT gateway or an internet gateway, and company policy forbids adding one. The instance role has CloudWatchAgentServerPolicy, yet the agent log shows connection timeouts and no metrics or log events arrive. What should the SysOps administrator do to fix this issue?

    Right. In the game that’s Renown for your Monitoring, Logging, Analysis, Remediation, and Performance Optimization building.

    Not that one: C is right. In the game your Monitoring, Logging, Analysis, Remediation, and Performance Optimization building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    Neither service needs any setting changed; traffic uses the endpoints once they exist.

    Written from docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/prerequisites.html

  2. A company runs the CloudWatch agent on 12 Linux servers in its own data center. The servers are not Amazon EC2 instances and are not registered with Systems Manager. A SysOps administrator must give the agent on each server the AWS permissions it needs to publish metrics and logs to CloudWatch. Which solution will meet these requirements?

    Right. In the game that’s Renown for your Monitoring, Logging, Analysis, Remediation, and Performance Optimization building.

    Not that one: B is right. In the game your Monitoring, Logging, Analysis, Remediation, and Performance Optimization building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    The agent looks for that profile by default on a server it runs in on-premises mode, so it signs its PutMetricData and PutLogEvents calls without any further setting. Because these are long-term keys, give the user only that policy and rotate or remove them when the servers are retired.

    Written from docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/prerequisites.html

  3. A SysOps administrator stored a CloudWatch agent configuration in Parameter Store as /platform/cwagent/linux. The 200 Amazon Linux instances are managed nodes whose role has AmazonSSMManagedInstanceCore and CloudWatchAgentServerPolicy. The administrator installed the agent with AWS-ConfigureAWSPackage, then ran AmazonCloudWatch-ManageAgent with the configure action and the ssm source pointing at that parameter. On every instance the configure step fails with an access denied error. Which action should the SysOps administrator take to fix this issue?

    Right. In the game that’s Renown for your Monitoring, Logging, Analysis, Remediation, and Performance Optimization building.

    Not that one: D is right. In the game your Monitoring, Logging, Analysis, Remediation, and Performance Optimization building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    Storing the same JSON as AmazonCloudWatch-linux and pointing the configure action at it lets every instance's agent download the configuration with the permissions it already has, which is the naming AWS recommends for agent configurations.

    Written from docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/prerequisites.html

Ask for something