Deploying Infrastructure from Git
This lesson explains Git as the source of truth for infrastructure code, and the AWS integrations, such as CloudFormation Git sync, that deploy directly from repositories.
Learning outcomes
After completing this lesson, you will be able to:
- Apply Git practices for infrastructure.
- Configure CloudFormation Git sync.
- Protect repositories and deployment credentials.
Git practices for infrastructure
Infrastructure code in Git gains history, review and rollback. Typical practices include short-lived feature branches merged through pull requests with required reviews and automated checks (template linting with cfn-lint, Guard rules, terraform validate and plan), tags for releases, and never committing secrets (use Secrets Manager or Parameter Store references). Reverting a commit and redeploying is a clean rollback. Repositories can be hosted on GitHub, GitLab, Bitbucket or AWS CodeCommit, which returned to general availability for new customers in November 2025.
CloudFormation Git sync
CloudFormation Git sync links a stack to a Git repository branch through an AWS CodeConnections connection (GitHub, GitLab, Bitbucket or GitHub Enterprise Server). The repository contains the template and a deployment file (YAML) that names the template path, parameters and tags. When a commit changes either file on the tracked branch, CloudFormation updates the stack automatically, without a pipeline, and can post change set comments on pull requests for review. Sync status and events are visible in the console. It suits teams that want GitOps-style deployments for individual stacks without designing a CI/CD pipeline, which the exam lists as out of scope.
# deployment file in the repository, e.g. deployments/web-prod.yaml
template-file-path: templates/web.yaml
parameters:
Env: prod
InstanceType: m7i.large
tags:
Application: web
Owner: platform-teamThe following diagram shows a change flowing from a pull request to the stack.

Protecting repositories and deployment credentials
When Git drives deployments, the repository becomes part of the production control plane: anyone who can merge to the tracked branch can change infrastructure. Branch protection rules therefore require pull requests, approving reviews and passing checks before a merge, and code owner files route changes to sensitive templates, such as IAM or network stacks, to the right reviewers.
The deployment itself should use short-lived credentials rather than access keys stored in the repository or the CI system. External CI systems such as GitHub Actions assume an IAM role through OIDC federation, with a trust policy restricted to the specific repository and branch. CloudFormation Git sync uses the CodeConnections connection and a role that CloudFormation assumes, which should have only the permissions that the stack needs. Secret scanning in the repository catches credentials that are committed by mistake.
Protecting infrastructure repositories
Rolling back a bad change
A merged pull request changes the health check path in a Git-synced stack, and the ALB marks all targets unhealthy. The on-call engineer reverts the merge commit on the main branch. Git sync detects the change and updates the stack back to the previous template within minutes, and the history in Git records who changed what and why, which also feeds the post-incident review.
Which feature deploys a CloudFormation stack when its template changes in Git?
Show answer
CloudFormation Git sync.
Exam Tips
Remember for the exam
- Use pull requests with automated linting and plan checks for infrastructure changes.
- Never commit secrets; reference Secrets Manager or Parameter Store.
- CloudFormation Git sync deploys a stack when its template or deployment file changes in Git.
- Git sync uses AWS CodeConnections to reach GitHub, GitLab or Bitbucket.