AWS Pipeline Deployment Patterns: Single- and Multi-Account Strategies
Pipeline deployment patterns for single- and multi-account environments
AWS Pipeline Deployment Patterns: Single- and Multi-Account Strategies
This guide explores the architectural patterns used to deliver code from a central CI/CD pipeline to one or more AWS accounts. Understanding these patterns is critical for the DOP-C02 exam, particularly regarding security isolation, blast radius reduction, and automation at scale.
Learning Objectives
After studying this guide, you should be able to:
- Distinguish between single-account and multi-account pipeline architectures.
- Configure cross-account IAM roles and S3 bucket policies for artifact sharing.
- Implement the centralized "Tooling Account" pattern for enterprise CI/CD.
- Manage KMS encryption keys for cross-account artifact access.
- Automate account onboarding using AWS Control Tower and Account Factory.
Key Terms & Glossary
- Tooling Account (Shared Services): A dedicated AWS account that hosts the CI/CD pipelines (CodePipeline, CodeBuild) and artifact repositories.
- Target Account: The environment account (e.g., Development, Staging, Production) where resources are actually deployed.
- Cross-Account Role: An IAM role in the target account that trusts the Tooling Account, allowing the pipeline to perform deployment actions.
- Artifact Store: An S3 bucket (usually in the Tooling account) that holds the output of build stages before they are deployed.
- Bucket Owner Full Control: A required S3 ACL setting when a pipeline in one account writes an artifact to be used by a role in another account.
The "Big Idea"
In a professional DevOps environment, isolation is safety. While a single-account setup is easier to manage, it lacks the security boundaries required for production. Multi-account patterns use AWS Organizations to separate environments (Dev, Test, Prod), ensuring that a misconfiguration or security breach in a development environment cannot impact the production system. The pipeline acts as the "secure bridge" between these isolated islands.
Formula / Concept Box
| Requirement | Mechanism | Implementation Detail |
|---|---|---|
| Access | IAM Cross-Account Role | Target account role trusts codepipeline.amazonaws.com or Tooling Account ID. |
| Artifacts | S3 Bucket Policy | Grant s3:Get* and s3:Put* to the cross-account role. |
| Encryption | KMS Key Policy | KMS Key must be in the Tooling account; Key Policy must allow Target Account Role to Decrypt. |
| Ownership | S3 ACLs | Deployment action must specify CannedACL: bucket-owner-full-control. |
Hierarchical Outline
- Single-Account Pattern
- Use Case: Small projects, startups, or local sandboxes.
- Pros: Simple IAM, no cross-account overhead, single billing.
- Cons: High blast radius; no strict isolation between Dev and Prod.
- Multi-Account Patterns
- Centralized Pipeline (Recommended): One "Tooling" account manages the flow to multiple target accounts.
- Decentralized Pipeline: Each account has its own pipeline (rarely used for large scale).
- Cross-Account Implementation Steps
- Step 1: Create S3 Bucket in Tooling Account (with KMS encryption).
- Step 2: Create IAM Role in Target Account (e.g.,
CrossAccountDeployRole). - Step 3: Update Tooling KMS Key Policy to allow Target Role to decrypt.
- Step 4: Configure CodePipeline Stage to assume the Target Role.
Visual Anchors
Centralized Pipeline Flow
IAM Trust Relationship (TikZ)
Definition-Example Pairs
- Pattern: Pipeline-to-Account Mapping
- Definition: The logic defining which branch/revision triggers a deployment to a specific environment.
- Example: A
mainbranch push triggers a deployment to the Staging account, while areleasetag triggers a deployment to the Production account via the same pipeline.
- Pattern: Cross-Account KMS
- Definition: Using a Customer Managed Key (CMK) in the Tooling account to encrypt artifacts that must be read by the Target account.
- Example: When CodeBuild finishes, it encrypts the ZIP artifact with
KMS-Key-A. CodeDeploy in the Prod account uses its cross-account role to callkms:DecryptusingKMS-Key-Ato access the code.
Worked Examples
Scenario: Configuring Cross-Account S3 Access
Problem: A pipeline in Account A (Tooling) needs to deploy a CloudFormation template to Account B (Production). The template is stored in an S3 bucket in Account A.
Step 1: The Bucket Policy (in Account A)
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::PROD_ACCOUNT_ID:role/DeployRole" },
"Action": [ "s3:Get*", "s3:List*" ],
"Resource": [ "arn:aws:s3:::artifact-bucket/*", "arn:aws:s3:::artifact-bucket" ]
}
]
}Step 2: The KMS Key Policy (in Account A)
You cannot use the default aws/s3 key for cross-account access. You must use a CMK.
{
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::PROD_ACCOUNT_ID:role/DeployRole" },
"Action": [ "kms:Decrypt", "kms:DescribeKey" ],
"Resource": "*"
}Checkpoint Questions
- Why can't you use the default managed KMS key (
aws/s3) for cross-account CodePipeline deployments? - In a multi-account setup, which account should host the CodePipeline resource itself?
- What is the purpose of the
RoleArnparameter in a CodePipeline stage configuration? - What S3 ACL must be applied to objects uploaded to a cross-account bucket to ensure the target account can manage them?
Muddy Points & Cross-Refs
- Bucket Owner Full Control: This is a common point of failure. If the Tooling account uploads an object to the Target account's bucket without this ACL, the Target account owner actually won't have permissions to delete or modify that object.
- Region vs. Account: Don't confuse multi-region with multi-account. You can have a single-account pipeline deploying to multiple regions, or a multi-account pipeline deploying within one region. For DOP-C02, expect questions that combine both (e.g., deploying to Prod-US-East-1 and Prod-EU-West-1 from a Tooling account).
Comparison Tables
| Feature | Single-Account | Multi-Account (Centralized) |
|---|---|---|
| Security | Low (Common Blast Radius) | High (Strict Isolation) |
| IAM Complexity | Low | High (Trust/Key Policies) |
| Governance | Difficult to enforce per-env | Easy via SCPs/Control Tower |
| Cost | Lower (less overhead) | Slightly higher (Account mgmt) |
| Best For | Prototyping | Enterprise Production |