AccessDenied on AWS IAM. what causes it and how to fix
| Service | AWS IAM |
|---|---|
| Cloud | Amazon Web Services (AWS) |
| Guide type | Procedure |
| Skill level | Intermediate to advanced |
| Time | 15 - 60 minutes depending on account size |
AccessDenied on AWS IAM, what causes it and how to fix on AWS IAM sits in the most-reported issues list across r/aws, AWS re:Post, and StackOverflow. The recovery path is mostly known, the AWS docs just bury it under three layers of conceptual material.
What accessdenied on aws iam, what causes it and how to fix actually involves on AWS IAM
The AccessDenied error from AWS typically surfaces with the message "Access Denied". The error code itself is what you grep for in AWS re:Post or in AWS Support cases, not the human-readable line.
On AWS IAM, this most often comes from one of three causes: a missing or restrictive IAM permission, a service-level limit you have hit, or a transient AWS-side capacity issue. The fix path differs by which.
The rest of this page is the structured fix path. Start with diagnose, then remediation, then the automation options so you do not have to do this by hand the next time it surfaces. Verify and safety sections at the end are the discipline that keeps the fix from regressing in production.
Identify
Look at the CloudTrail event for the failed call, even if you are not enrolled in CloudTrail Lake. The basic 90-day event history works for most diagnostic purposes and lives in the console under CloudTrail > Event history. Filter by event name (the API action) and time range; the event JSON shows the exact user identity, source IP, request parameters, and error code.
Pull the AWS request ID from the response headers: x-amz-request-id for most services, x-amzn-RequestId for API Gateway, both x-amz-request-id and x-amz-id-2 for S3. AWS Support needs these IDs to look up your call in their internal logs - without them, the first reply on a ticket will ask you to reproduce the call and capture them. Save them with a timestamp; AWS Support cannot retrieve calls older than 90 days for most services.
Check the AWS Health Dashboard at health.aws.amazon.com for ongoing service events in your region. About one in ten user-reported outages turn out to be region-scoped AWS service degradation already being tracked. AWS Health also exposes an API and EventBridge events, so you can wire a Lambda hook that pages on-call only when the failure correlates with an active AWS Health event in the same region and service.
Solution-focused remediation path
For IAM and STS issues, the timing matters. STS sessions can take up to 60 seconds to propagate after creation. The first call right after assume-role can fail with a permission error even when the policy is correct. Add a small retry with backoff before treating the first failure as definitive.
When the failure happens in production but not in dev, do not just compare the IAM policy. Compare the SCP / RCP at the OU level, the permission boundary on the role, and the resource-based policy on the target. One of those is almost always different between accounts. AWS Config conformance packs make this comparison routine.
Most AWS IAM failures fall into one of three buckets: IAM permission gap, networking path break (security group, NACL, or VPC endpoint policy), or service-limit / quota hit. Run that mental triage first - it covers around 80 percent of real-world cases. If the failure does not fit any of the three, it is likely a service-side regression worth opening a re:Post or support ticket for.
Automate this fix so you do not do it twice
Codify the fix in Terraform or CloudFormation
When you reach for the console to fix the same issue twice, the third occurrence should be solved in IaC, not in the console. Terraform's terraform import and CloudFormation's resource importer let you adopt the existing resource into state without recreating it. Lock the corrected attribute behind a variable so the next operator does not have to rediscover the value. Add a moved {} block or CloudFormation resource refactor to keep the diff clean.
Add a CloudWatch alarm so you know next time
The cheapest way to never see the same incident twice is a CloudWatch alarm on the metric that would have warned you. For AWS IAM, the relevant metrics live under AWS/iam namespace or under custom metrics published by your Lambda or ECS task. Set thresholds based on observed normal range plus one or two standard deviations, not on round-number guesses. CloudWatch anomaly-detection alarms remove the threshold-guessing problem entirely for metrics with regular seasonality.
Automate the fix with Python and boto3
For anything you do more than twice, write a small Python script. The boto3 pattern below uses paginators (so it does not blow up on accounts with thousands of resources), explicit region binding, and a dry-run flag that defaults to True. Keep the script under 100 lines; if it grows beyond that, you are building a tool and should put it behind a Lambda with proper logging.
import boto3, sys
DRY_RUN = '--apply' not in sys.argv
client = boto3.client('iam', region_name='us-east-1')
paginator = client.get_paginator('describe_...')
for page in paginator.paginate(): for item in page.get('Items', []): if item.get('Status') == 'FAILED': if DRY_RUN: print(f'[dry-run] would fix {item["Id"]}') else: client.modify_...(ResourceId=item['Id']) print(f'fixed {item["Id"]}')
Pitfalls to dodge
A subtle pitfall on AWS IAM is that the AWS Console and the SDK can disagree about resource state during a configuration change. Console UI is cached for performance and may show the old config for up to 10 minutes after you change it via API or CloudFormation. Always confirm with describe-* CLI calls during a change window, not with screenshots from the Console.
The other pitfall: assuming that an automated remediation is correct because it succeeded. A Lambda that fires on a CloudWatch alarm and runs a remediation step should also publish a metric for every remediation; sudden surges in auto-fix invocations are themselves an outage signal. Otherwise you can hide a slow-burn regression behind a quiet remediation loop for weeks.
Resolve
- Reproduce the original symptom path. If it still surfaces in any account or region or IAM role, you have not fixed it.
- Watch for 24 to 48 hours. AWS metrics and policy systems can mask issues with cached health for 6 to 12 hours, especially CloudFront and Route 53.
- Run a smoke test under realistic load. Happy-path tests miss race conditions and IAM session-cache issues.
- Capture the new state in a runbook so the next person on call does not have to rediscover this. Push it to Confluence or your team wiki, not into Slack.
- If the fix involved a permission change, run IAM Access Analyzer one more time to confirm you did not open a separate hole while closing this one.
Safety, rollback, blast radius
- Test in a non-production account if your environment has Control Tower or AWS Organizations. The cost of one sandbox account is cheaper than one rollback meeting.
- Export the existing config before changing it. Most AWS IAM resources support describe + export to JSON via CLI - capture that to source control before you start.
- Know your rollback path. Some AWS IAM operations are one-way (region migration, account-level feature opt-in, KMS key deletion past pending window). Confirm reversibility on the AWS doc before you commit.
- Be aware of cross-service impact. IAM role changes ripple to every service trusting that role. KMS key changes break every workload depending on that key. VPC endpoint changes affect every VPC consumer of that endpoint.
- Maintenance window discipline: if the change touches DNS, certificate rotation, or anything that emits TLS handshakes, line up a window with stakeholder notification, not a heroic mid-day swap.
FAQ
aws iam describe-... first, then commit it before you change anything. A few operations are one-way (KMS key deletion past the pending window, region migration, account closure). Check the AWS doc for the specific API before you commit.aws CLI or SDK calls - those almost always still work.References
- docs.aws.amazon.com - official documentation for AWS IAM
- AWS re:Post (formerly forums) - community Q&A with AWS-staff-verified answers
- AWS Health Dashboard at health.aws.amazon.com
- AWS Service Quotas console and AWS Well-Architected Tool
Related fixes
Related guides worth a look while you sort this one out:
- EntityAlreadyExists on AWS IAM, what causes it and how to fix
- ExpiredToken on AWS IAM, what causes it and how to fix
- InvalidClientTokenId on AWS IAM, what causes it and how to fix
- MalformedPolicyDocument on AWS IAM: what causes it and how to fix
- PassRoleDenied on AWS IAM: what causes it and how to fix
- PolicySizeLimitExceeded on AWS IAM: what causes it and how to fix