Interview Prep/Terraform/Authentication and Cloud API Errors

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.

All Terraform questions

More on Authentication and Cloud API Errors