Q: Your CodeBuild job is failing with a permissions error when trying to push to ECR. What do you check?
CodeBuild uses a service role. That role needs ECR permissions:
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: "When an interviewer asks how I troubleshoot this in AWS, I frame it through my hands-on production experience. 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
CodeBuild uses a service role. That role needs ECR permissions:
ecr:GetAuthorizationToken— to authenticate with ECR.ecr:BatchCheckLayerAvailability,ecr:PutImage,ecr:InitiateLayerUpload, etc. — to push layers.
Remediation & Permanent Safeguards
In the CodeBuild buildspec.yml, the login command: This requires ecr:GetAuthorizationToken at minimum. Check the service role policy. Also check: ECR repository policy — cross-account pushes need a resource policy on the ECR repo too.
aws ecr get-login-password | docker login --username AWS --password-stdin <account>.dkr.ecr.<region>.amazonaws.com
- ecr:GetAuthorizationToken — to authenticate with ECR.
- ecr:BatchCheckLayerAvailability, ecr:PutImage, ecr:InitiateLayerUpload, etc. — to push layers.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Purging compromised IAM user credentials immediately prior to querying CloudTrail forensic event logs when configuring CodeBuild failing permissions Deactivating a compromised key prevents abuse while preserving identity records for CloudTrail forensic queries to assess blast radius.
- Conflating local IAM Permissions Boundaries with organizational Service Control Policies (SCPs) when configuring CodeBuild failing permissions SCPs define maximum permission guards at the AWS Organization level across accounts, whereas permission boundaries limit delegate privileges within a single account.
- Deploying single-AZ cloud infrastructure for production workloads without multi-AZ failover resilience when configuring CodeBuild failing permissions Availability Zone hardware failures or localized network partitions cause complete service downtime when resources are not distributed across >=2 AZs.
- Jumping straight to SSH or instance restarts without reviewing CloudWatch metrics and AWS Systems Manager logs when configuring CodeBuild failing permissions Senior SREs triage control plane and hypervisor metrics via CloudWatch and SSM Session Manager before executing invasive host-level actions.