2.4 Troubleshooting Security Telemetry & Log Ingestion
Key Takeaways
The CloudWatch Unified Agent requires explicit IAM instance profile permissions (logs:CreateLogStream, logs:PutLogEvents, logs:DescribeLogStreams) and network line-of-sight to regional CloudWatch endpoints.
Amazon API Gateway logging fails silently unless an IAM role with the AmazonAPIGatewayPushToCloudWatchLogs managed policy is configured in the global regional API Gateway Account Settings.
AWS Lambda execution roles require logs:CreateLogGroup, logs:CreateLogStream, and logs:PutLogEvents permissions, and KMS key policies on encrypted log groups must explicitly grant access to
logs.<region>.amazonaws.com.VPC Flow Logs delivered to S3 require the delivery.logs.amazonaws.com service principal with aws:SourceAccount conditions, whereas CloudTrail requires cloudtrail.amazonaws.com with bucket-owner-full-control ACL enforcement.
CloudFront standard logging (legacy) to S3 needs a bucket with ACLs enabled (not Bucket owner enforced); SSE-KMS works only with a customer managed key whose key policy lets delivery.logs.amazonaws.com call kms:GenerateDataKey*, never with aws/s3.
Systematic Troubleshooting Methodology for Security Telemetry
Security telemetry pipelines fail for predictable architectural reasons: IAM authorization failures, service principal mismatches in resource policies, network line-of-sight blockages, and incompatible cryptographic configurations. For the AWS Certified Security – Specialty examination, you must possess the ability to rapidly isolate the root cause when logs fail to deliver.
[ Log Source ] ──> (1. IAM / Trust) ──> (2. Network / Endpoints) ──> (3. Service Principal) ──> (4. KMS Encryption) ──> [ Destination ]
When a telemetry stream ceases or fails to initialize, evaluate these four layers systematically:
- Identity & Execution Role: Does the entity producing the logs have permissions to call
PutLogEventsor assume the logging role? - Network Path: Can the client establish TLS sessions to
logs.<region>.amazonaws.comthrough NAT or VPC Endpoints? - Resource / Bucket Policy: Does the receiving S3 bucket policy trust the exact AWS service principal and satisfy all condition keys?
- Cryptographic Key Policy: Does the destination KMS key policy grant
kms:GenerateDataKey*andkms:DescribeKeyto the delivering service with the proper encryption context?
Diagnosing CloudWatch Unified Agent Failures
The Amazon CloudWatch Unified Agent is installed on EC2 instances and on-premises servers to collect system metrics and log files (e.g., /var/log/secure, /var/log/audit/audit.log, Windows Event Logs). When log streams fail to appear in CloudWatch Logs, investigate the following failure modes:
1. Missing or Inadequate IAM Permissions
The EC2 instance profile must have an attached IAM policy granting CloudWatch Logs write operations. Attach the AWS-managed policy CloudWatchAgentServerPolicy or a scoped custom policy containing:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogStreams"
],
"Resource": "arn:aws:logs:*:*:*"
}
]
}
2. Host-Level File Permissions
The Unified Agent typically runs as a dedicated non-root service account (cwagent). If target operating system log files (such as /var/log/audit/audit.log) have file permissions set to 0600 owned strictly by root:root, the cwagent process cannot read the file. The local agent log (/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log) will report open /var/log/audit/audit.log: permission denied.
3. Network Line-of-Sight & VPC Endpoints
EC2 instances residing in private subnets without an internet gateway or NAT gateway cannot reach the public CloudWatch Logs regional API. You must provision an Interface VPC Endpoint (com.amazonaws.<region>.logs). Common pitfalls include:
- Security Group on the VPC Endpoint: The security group attached to the Interface Endpoint must permit inbound TCP port 443 from the private subnet CIDR.
- Private DNS: Private DNS must be enabled on the VPC Endpoint so that SDK and agent calls to
logs.<region>.amazonaws.comresolve automatically to the endpoint's private IP addresses.
API Gateway Execution & Access Logging Failures
Amazon API Gateway supports two types of logging:
- Access Logging: Logs client caller identity, request path, IP address, and response latency.
- Execution Logging: Logs detailed internal execution steps, authorizer execution, request/response transformation, and integration backend errors.
The Global Account Settings Trap
A frequent point of failure is that enabling execution or access logging on an individual API stage appears to succeed in the console, but no log groups or log streams are ever created in CloudWatch Logs.
Root Cause: API Gateway requires an IAM role configured globally at the API Gateway Account Settings level for that region. API Gateway cannot assume a role specified per-stage; it relies on a regional account-level role.
[ API Gateway Console / API ]
└── Settings
└── CloudWatch log role ARN: arn:aws:iam::111122223333:role/APIGatewayLoggingRole
The IAM role must have a trust relationship allowing apigateway.amazonaws.com:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "apigateway.amazonaws.com" },
"Action": "sts:AssumeRole"
}
]
}
And it must have the managed policy AmazonAPIGatewayPushToCloudWatchLogs attached, granting logs:CreateLogGroup, logs:CreateLogStream, logs:PutLogEvents, and logs:DescribeLogStreams.
Full Request/Response Data Tracing Security Risk
When enabling Execution Logging, administrators can enable Log full requests/responses data. While invaluable for debugging, this logs entire request bodies, query strings, and headers into plaintext CloudWatch Logs. If requests contain passwords, API keys, or credit card numbers, this creates an unmasked compliance violation.
AWS Lambda Execution Role Permissions
When an AWS Lambda function executes, it streams execution outputs (stdout, stderr, and runtime errors) to a default log group named /aws/lambda/<function-name>.
Required IAM Actions
The Lambda function's execution role must contain:
logs:CreateLogGrouplogs:CreateLogStreamlogs:PutLogEventsThese are included in the AWS-managed policyAWSLambdaBasicExecutionRole.
Encrypted Log Groups with Customer Managed Keys (CMK)
If the CloudWatch Log Group is encrypted with an AWS KMS Customer Managed Key, who needs KMS permissions? This is a classic exam question.
- The Lambda execution role does NOT require KMS permissions to write logs. The Lambda runtime passes log data to the CloudWatch Logs service.
- The CloudWatch Logs Service Principal (
logs.<region>.amazonaws.com) MUST be granted KMS permissions in the KMS Key Policy:
{
"Sid": "AllowCloudWatchLogsKeyAccess",
"Effect": "Allow",
"Principal": { "Service": "logs.us-east-1.amazonaws.com" },
"Action": [
"kms:Encrypt*",
"kms:Decrypt*",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:DescribeKey"
],
"Resource": "*",
"Condition": {
"ArnLike": {
"kms:EncryptionContext:aws:logs:arn": "arn:aws:logs:us-east-1:111122223333:log-group:*"
}
}
}
S3 Bucket Policy & KMS Key Policies: CloudTrail vs. VPC Flow Logs
When log services deliver directly to Amazon S3, you must use the correct service principal. Using the wrong service principal in the bucket policy causes delivery to fail with Access Denied.
| Log Service | Correct Service Principal | Required S3 Bucket Actions | Critical Condition Keys |
|---|---|---|---|
| AWS CloudTrail | cloudtrail.amazonaws.com | s3:GetBucketAcl, s3:PutObject | s3:x-amz-acl: bucket-owner-full-control, aws:SourceArn or aws:SourceAccount |
| VPC Flow Logs (to S3) | delivery.logs.amazonaws.com | s3:GetBucketAcl, s3:PutObject | aws:SourceAccount |
| VPC Flow Logs (to CloudWatch) | vpc-flow-logs.amazonaws.com | Assumes an IAM Role with logs:PutLogEvents | Trust policy on IAM role for vpc-flow-logs.amazonaws.com |
Exam Trap: A common distractor on the exam proposes configuring
vpc-flow-logs.amazonaws.comin an S3 bucket policy. This will fail! When VPC Flow Logs writes to Amazon S3, AWS uses the Log Delivery service, whose service principal isdelivery.logs.amazonaws.com.
Confused Deputy Prevention with aws:SourceArn
To prevent an adversary from abusing an AWS service to write unauthorized data to your audit bucket, always include aws:SourceArn or aws:SourceAccount in your bucket policy condition blocks.
CloudFront Logging Debugging: Standard vs. Real-Time Logs
Amazon CloudFront provides two distinct logging mechanisms with fundamentally different operational constraints.
Standard Access Logs (S3 Delivery)
Standard logs are delivered as compressed gzip files within minutes to an hour or so. The original S3 delivery is now labelled standard logging (legacy); the newer standard logging (v2) can also send the same records to CloudWatch Logs or Amazon Data Firehose.
The two bucket traps in legacy S3 delivery:
- ACLs must be enabled. CloudFront grants the
awslogsdeliveryaccountFULL_CONTROLthrough the bucket ACL. New buckets default to S3 Object Ownership Bucket owner enforced, which disables ACLs, so logs never arrive until ACLs are enabled on that bucket. - KMS key choice. SSE-S3 always works. SSE-KMS works only with a customer managed key whose key policy allows the
delivery.logs.amazonaws.comservice principal to callkms:GenerateDataKey*(pluskms:Decryptif S3 Bucket Keys are enabled). The AWS managed keyaws/s3cannot be used, because its policy can't be edited.
Real-Time Logs (Kinesis Data Streams Delivery)
Real-time logs deliver configurable access data within seconds to Amazon Kinesis Data Streams.
- Requires an IAM role that CloudFront assumes to write records.
- The IAM role trust policy must grant
sts:AssumeRoletocloudfront.amazonaws.com. - The IAM permissions policy must grant
kinesis:PutRecordandkinesis:PutRecordson the stream ARN. - If the Kinesis data stream uses SSE-KMS, the IAM role that CloudFront assumes must also be allowed to use that key (for example,
kms:GenerateDataKey).
A security engineer turns on CloudFront standard logging (legacy) with an S3 bucket as the destination. The bucket was created last week with default settings, and the team then set its default encryption to SSE-KMS with the AWS managed key aws/s3. Several days pass, but no log files appear. The bucket exists and the logging configuration was published. What is the most likely cause of this failure?
The CloudFront distribution is configured with price class 100, which automatically disables access logging.
The S3 bucket has Amazon S3 Versioning enabled, which blocks the CloudFront delivery service from overwriting files.
CloudFront standard access logs require Amazon Data Firehose as an intermediary before writing to S3.
The bucket's defaults block delivery: ACLs are disabled (Bucket owner enforced), which legacy CloudFront logging needs, and CloudFront cannot write with aws/s3. Enable ACLs and use SSE-S3 or a customer managed key whose policy allows delivery.logs.amazonaws.com.
A developer deploys a REST API using Amazon API Gateway and enables execution logging and access logging on the 'prod' stage. However, testing reveals that no log groups or streams are created in Amazon CloudWatch Logs. Other serverless components in the account log successfully. What configuration step was omitted?
The developer forgot to attach the AWSLambdaBasicExecutionRole policy to the API Gateway stage.
The developer did not configure an IAM role with the AmazonAPIGatewayPushToCloudWatchLogs policy in the API Gateway Account Settings for that region.
The developer failed to create an Interface VPC Endpoint for CloudWatch Logs inside the API Gateway management VPC.
The API Gateway stage was not deployed with active AWS X-Ray tracing enabled.
An enterprise requires all VPC Flow Logs to be centralized in an Amazon S3 bucket located in a central security account. The security engineer creates the flow log subscription in a member account pointing to the S3 bucket, but the flow log status displays 'Access Denied'. Which service principal must be granted s3:PutObject permissions in the destination S3 bucket policy?
vpc-flow-logs.amazonaws.com
cloudtrail.amazonaws.com
delivery.logs.amazonaws.com
flow-logs.delivery.amazonaws.com
An EC2 instance in a private subnet is running the CloudWatch Unified Agent to stream /var/log/messages to CloudWatch Logs. The instance profile has CloudWatchAgentServerPolicy attached, and local agent logs confirm log parsing is active, yet no log streams appear in CloudWatch Logs. The VPC has no internet gateway or NAT gateway. What is the root cause of the delivery failure?
The private subnet lacks an Interface VPC Endpoint for CloudWatch Logs (com.amazonaws.<region>.logs), preventing the agent from establishing network connections to the CloudWatch API.
The CloudWatch Unified Agent requires an active AWS Direct Connect connection to stream system logs from Linux instances.
CloudWatch Logs only accepts log streams delivered over UDP port 514 syslog protocols.
The EC2 instance profile must have the AdministratorAccess policy attached because CloudWatchAgentServerPolicy only supports metric collection.
Sections you finish are checked off in the contents.