The Simplest Way to Make AWS CloudFormation and GitLab CI Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Using aws cloudformation and gitlab ci lets your team build cloud stacks from code commits. GitLab runs the build pipeline, and CloudFormation creates or updates your cloud resources. This workflow turns manual cloud changes into reviewed pull requests. Every change goes through the same pipeline before it reaches your live cloud account. Teams get a clear record of what changed and when the pipeline ran. How aws cloudformation and gitlab ci share roles and data The link between aws cloudfor

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Using aws cloudformation and gitlab ci lets your team build cloud stacks from code commits. GitLab runs the build pipeline, and CloudFormation creates or updates your cloud resources.

This workflow turns manual cloud changes into reviewed pull requests. Every change goes through the same pipeline before it reaches your live cloud account. Teams get a clear record of what changed and when the pipeline ran.

How aws cloudformation and gitlab ci share roles and data

The link between aws cloudformation and gitlab ci starts with trust between the two platforms. GitLab runners need permission to call the cloud API and update stacks. In a clean setup, GitLab sends a signed identity token to the cloud provider.

The cloud provider checks this token against a trust rule on an identity role. If the project path and branch match the rule, the runner gets temporary keys. The runner then sends the template file and input values to the stack service.

Next, the cloud service reads the template and compares it to the active stack. It builds a change list that shows which resources will start, change, or stop. The runner waits for the stack update to finish and reads the status logs. If a resource fails to start, the cloud service rolls the stack back. It then reports the error back to the pipeline job log.

Common failure modes and how to scope roles

Many teams start by saving long-lived cloud keys inside GitLab project settings. This shortcut creates a big risk for your production cloud accounts. Static keys do not expire on their own, and anyone with project admin rights can copy them.

Shared runner accounts also cause trouble when one role controls every cloud service. If a bad template runs on a branch, it can delete live databases or networks. Unlogged manual changes outside the pipeline also cause stack drift and broken deployments.

GitLab CI Security + AWS IAM Policies: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

To fix this, swap static keys for open identity tokens with short lifetimes. Scope each cloud role to one GitLab repo and one target branch. Give the runner role only the rights needed to manage stack events. Pass a separate execution role to the stack service so it builds the actual resources.

Managing network paths and database tasks in pipelines

Cloud stacks often set up private networks, compute nodes, and locked databases. Soon after the stack finishes, the pipeline often needs to run database migrations or check app health. This step fails when the runner sits outside your private cloud network.

Some teams open public network ports so the runner can reach the database. Others put self-hosted runners inside the private network with broad network rules. A shared runner inside your private network can reach every system in that subnet.

Keep your private databases closed to the public internet at all times. Split stack updates from database schema jobs so each step uses its own tight role. Log every query and command that runs during a deployment job for later review. Mask sensitive fields like emails, phone numbers, card numbers, and national IDs in job outputs so masking rewrites matched fields in results.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

How should GitLab runners log in to AWS without static keys?

Use OpenID Connect so GitLab sends a short-lived job token to the cloud identity service. The cloud account checks the repo and branch claims before it hands back temporary keys.

Why should we split the runner role from the stack role?

Splitting roles stops a pipeline job from making direct API calls to your cloud resources. The runner only starts the stack update, while the stack service holds the rights to build resources.

How can we stop test branches from changing live cloud stacks?

Lock your production cloud role trust rules to the main branch name only. Set up a separate cloud account and role for test branches so tests stay isolated.

The query runs. The emails stay hidden.