Q: A Lambda function is failing with `Access Denied` when trying to write to DynamoDB. How do you fix it?
Lambda functions use an execution role (IAM role). This role needs dynamodb:PutItem (or broader dynamodb:) permission on the target table.
Want to master this scenario in a live sandbox? Stephane Maarek's AWS Certified DevOps Engineer Professional Masterclass on Udemy covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: "In our AWS cloud environment, we managed high-traffic microservices where this exact scenario occurred. When addressing this question, I walk the interviewer through our production incident runbook: isolating the blast radius, checking diagnostic logs and metrics, and applying a safe fix."
Initial Diagnostics & Root Cause Analysis
Lambda functions use an execution role (IAM role). This role needs dynamodb:PutItem (or broader dynamodb:*) permission on the target table.
- Go to Lambda → Configuration → Permissions → click the execution role name.
- In IAM, add an inline policy or attach a managed policy with DynamoDB permissions.
Remediation & Permanent Safeguards
Fix: Example policy: Always scope the Resource to the specific table ARN, not *. Principle of least privilege.
{
"Effect": "Allow",
"Action": ["dynamodb:PutItem", "dynamodb:GetItem"],
"Resource": "arn:aws:dynamodb:us-east-1:123456789:table/MyTable"
}
- Go to Lambda → Configuration → Permissions → click the execution role name.
- In IAM, add an inline policy or attach a managed policy with DynamoDB permissions.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Raising provisioned read/write capacity blindly instead of isolating hot partition keys in DynamoDB Individual DynamoDB partitions enforce hard throughput limits (1,000 WCU / 3,000 RCU); table-level capacity increases cannot resolve single-key hot partitions.
- Expecting strongly consistent reads from a Global Secondary Index (GSI) DynamoDB GSIs are updated asynchronously and only support eventually consistent reads; code demanding immediate read-after-write consistency will read stale data.
- Storing large unstructured payloads (>400KB) directly in DynamoDB items instead of offloading to Amazon S3 DynamoDB strictly caps item size at 400KB; storing large attributes inflates RCU/WCU consumption and degrades throughput compared to S3 claim-check patterns.
- Using scan filters with projection expressions expecting reduced RCU consumption in aws-q021-a-lambda-function-is-failing-with-a DynamoDB charges RCUs based on the total size of items evaluated before the filter expression is applied, not the filtered payload returned to the client.