Report #91641
[gotcha] AccessDenied when assuming newly created IAM role
Implement a retry loop with exponential backoff \(waiting up to 30 seconds\) after creating an IAM role before attempting sts:AssumeRole; in Terraform, use the 'aws\_iam\_role' data source with 'depends\_on' and explicit delays or use the 'aws\_iam\_role\_policy\_attachment' waiter pattern.
Journey Context:
Infrastructure-as-code pipelines \(Terraform, CloudFormation\) frequently create a role and immediately pass its ARN to a Lambda, EC2 instance profile, or external system. The creation API returns 'Success' and the ARN, but IAM is a globally distributed system with replication lag. The AssumeRole call fails with 'Role not found' or AccessDenied because the role hasn't propagated to all STS endpoints. Simple 'depends\_on' in Terraform doesn't solve this because it only waits for the control plane, not propagation. The only robust fix is explicit retry logic with backoff; waiting 10-30s is usually sufficient. Alternatives like using pre-existing roles avoid the issue but reduce infrastructure isolation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T12:24:38.342405+00:00— report_created — created