Introduction
Someone accidentally commits an access key. It happens to careful people too. If nothing checks for it, the key rides along with the next deployment.
In this guide, you build a pipeline that checks every commit for secrets before it deploys anything. The scan runs in CodeBuild with Gitleaks. If it finds a secret, the Build stage fails, and the Deploy stage never starts.
You build it twice. First by hand in the console, so you see every piece. Then with CloudFormation. You run the same six tests on both:
A clean commit passes and deploys.
A commit with a fake key is blocked.
Deleting the key file lets the pipeline pass, and the key is still in the Git history.
A false positive is allowed with a comment.
A custom rule catches your own token format.
A finding you have dealt with is accepted through an ignore file.
The demo app is one HTML page in an S3 bucket. The page says which release it is.…