Lambda create fails with `InvalidParameterValueException: The role defined for the function cannot be assumed by Lambda.` right after Terraform created the role.
IntermediateTroubleshootingAuthentication and Cloud API Errors
Answer
Likely causes → IAM eventual consistency: the role exists but hasn't propagated to Lambda yet. Or the trust policy doesn't list lambda.amazonaws.com.
Diagnose → Retry after a minute; if it still fails, check the trust policy.
Fix → Re-run apply (usually succeeds). The AWS provider retries for a while; if not enough, add a short time_sleep depending on the role and policy attachments.
Prevent → Make the function depend on the policy attachments too (depends_on = [aws_iam_role_policy_attachment.logs]), and keep providers updated for better retry logic.
More on Authentication and Cloud API Errors
`Error: No valid credential sources found` followed by `no EC2 IMDS role found ... context deadline exceeded`.Beginner`Error: Cannot assume IAM Role` — `api error AccessDenied: User: arn:aws:iam::111111111111:user/ci is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::222222222222:role/terraform`.IntermediateGitHub Actions: `Could not assume role with OIDC: Not authorized to perform sts:AssumeRoleWithWebIdentity`.IntermediateGitHub Actions log says `It looks like you might be trying to authenticate with OIDC. Did you mean to set the id-token permission?`BeginnerApplies that run longer than an hour fail with `ExpiredToken: The security token included in the request is expired`.Intermediate`InvalidClientTokenId: The security token included in the request is invalid.`Beginner