ERROR REFERENCE
CodeBuild cannot use the configured CodeConnections connection
CloudFormation reached CodeBuild, but the project could not use the source connection while it was being created. This is usually a CodeBuild project-role or connection-readiness problem, not a reason to widen the role that launched the deployment.
WHAT IT MEANS
What this error means
User is not authorized to access connection [REDACTED_ARN]
(Service: AWSCodeBuild; Status Code: 400; Error Code: OAuthProviderException)
The CodeBuild resource handler rejected the configured CodeConnections source connection. The project service role may not be allowed to read the connection token, the connection may not be available in the target account or Region, or a policy attached in the same stack may not have propagated before project creation.
FIX
How to fix it
-
Find the two identities and the connection:
record the CodeBuild project's service role, the connection ARN,
and the account and Region used by the deployment. Do not inspect
only the role that runs
sam deploy. -
Read the CodeBuild role policies (read-only):
For a CodeConnections source, check the policy foraws iam list-role-policies --role-name <codebuild-role> aws iam list-attached-role-policies --role-name <codebuild-role>codeconnections:GetConnectionandcodeconnections:GetConnectionToken. Some service paths also requirecodeconnections:UseConnectionscoped to the connection. -
Check the connection itself (read-only):
Confirm that it is available, belongs to the target account (or is intentionally shared), and uses the provider expected by the CodeBuild source configuration.aws codeconnections get-connection --connection-arn <connection-arn> - Fix stack ordering when the role is created with the project. Make the CodeBuild project depend on the role policy attachment, then retry after IAM propagation. A policy on the deployment role cannot replace permissions on the project role.
See the AWS guides for the CodeBuild GitHub App connection flow and the CodeConnections action reference.
AUTOMATE THE TRIAGE
Diagnose this automatically
SAM Doctor recognizes the AWSCodeBuild OAuthProviderException (high confidence), keeps it separate from generic CloudFormation resource failures, and shows the project-role and connection checks. Runs locally; no AWS access, no log upload.
python -m pip install sam-doctor
sam-doctor diagnose deployment.log --format markdown
RELATED
Related errors
- AWS denied an API action required by the deployment - a generic IAM denial without the CodeBuild connection context.
- CloudFormation resource creation or update failed - the generic fallback for other resource-handler failures.