DOP-C02 Security and Compliance Practice Question
A DevOps engineer needs to allow an AWS Lambda function to write logs to Amazon CloudWatch Logs. What should the engineer do?
⚠ Common exam trap
DOP-C02 often tests the misconception that Lambda uses instance profiles like EC2, or that resource-based policies on log groups can grant write access — both are wrong; permissions must come from the execution role.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Attach an IAM policy to the Lambda execution role that allows logs:CreateLogGroup, logs:CreateLogStream, and logs:PutLogEvents.
Lambda functions assume an IAM execution role, and permissions to write to CloudWatch Logs must be granted via an IAM policy attached to that role. The policy needs logs:CreateLogGroup, logs:CreateLogStream, and logs:PutLogEvents to allow the function to create the log group (if absent), create a log stream, and put log events. This is the standard, least-privilege way to grant Lambda logging permissions.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Attach an IAM role to the Lambda function's instance profile.
Why it's wrong here
Lambda functions do not have instance profiles; that construct is used by Amazon EC2 instances to deliver temporary credentials via the instance metadata service. An execution role is instead attached to the function at the service level, and the Lambda service assumes it using a trust policy. Adding an IAM role to an 'instance profile' would not give the function any CloudWatch Logs permissions and is an invalid configuration.
- ✓
Attach an IAM policy to the Lambda execution role that allows logs:CreateLogGroup, logs:CreateLogStream, and logs:PutLogEvents.
Why this is correct
The execution role is the IAM identity that the Lambda service assumes on the function's behalf, and you must attach an identity-based policy with logs:CreateLogGroup, logs:CreateLogStream, and logs:PutLogEvents. Without these actions, CloudWatch Logs will reject the function's log writes, causing request failures and missing log streams. This is the standard, least-privilege pattern for granting Lambda access to CloudWatch Logs in the same account.
- ✗
Generate an access key for the Lambda function and configure the function to use it.
Why it's wrong here
Access keys are long-term credentials that belong to IAM users, not to Lambda functions; Lambda does not have access keys and cannot use them natively. Embedding an access key in function code or environment variables would create a severe security risk and is antithetical to the execution-role model. The service instead obtains short-lived temporary credentials from the function's execution role via STS.
- ✗
Create a resource-based policy on the CloudWatch Logs log group that allows the Lambda function to write.
Why it's wrong here
A resource-based policy on the CloudWatch Logs log group controls who can perform operations on that log group, but it does not grant the Lambda service permission to assume the function's execution role or to call logs:PutLogEvents on the function's behalf. Resource-based policies are primarily used for cross-account subscriptions or when an external service like Amazon Kinesis Firehose must deliver to the log group. For same-account Lambda logging, identity-based permissions on the execution role are required and are the supported mechanism.
Quick reference
Cloud Service Model Comparison
| Model | You Manage | Provider Manages | Examples |
|---|---|---|---|
| IaaS | OS, runtime, apps, data | Hardware, hypervisor, networking | EC2, Azure VMs, GCP Compute Engine |
| PaaS | Apps and data | OS, runtime, middleware, hardware | Elastic Beanstalk, Azure App Service |
| SaaS | Data and settings only | Everything else | Microsoft 365, Salesforce, Workday |
| FaaS / Serverless | Function code only | Infra, scaling, runtime | Lambda, Azure Functions, Cloud Run |
| CaaS | Containers and apps | Kubernetes, OS, hardware | EKS, AKS, GKE |
Go deeper
Related to this question
About these practice questions
This DOP-C02 question is part of Courseiva's 1,298-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Amazon Web Services exam blueprint
This DOP-C02 practice question is part of Courseiva's free Amazon Web Services certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DOP-C02 exam.