Amazon DOP-C02: Infrastructure as Code and Configuration Management — Study Guide

Part of the AWS DevOps Engineer Professional DOP-C02 — Study Guide. Practice with verified answers in the Amazon exam hub, or take timed practice tests on ExamRoll.io.

Overview

Infrastructure as Code (IaC) and configuration management on AWS provide repeatable, auditable, and governed provisioning and configuration of infrastructure and applications. CloudFormation and the AWS Cloud Development Kit (CDK) describe resources declaratively or via code that synthesizes to CloudFormation. Configuration layers such as AWS OpsWorks and AWS Systems Manager enforce and report desired state on instances across EC2 and hybrid fleets. Secrets, parameters, and image-baking complete the lifecycle, enabling immutable, secure deployments at scale.

CloudFormation Stacks, Change Control, and Governance

CloudFormation stacks are the unit of deployment. Design stacks around lifecycle boundaries and ownership to minimize blast radius. Use parameters sparingly and prefer opinionated defaults with mappings or SSM lookups. Export and import only stable, shared values via Outputs and Fn::ImportValue to avoid tight coupling.

Nested stacks encapsulate reusable components and keep parent templates small. A parent stack can pass parameters to child stacks and consume their outputs, enabling modular architectures (for example, a shared-network nested stack consumed by an application stack). Keep nested stacks focused on a single concern (VPC, data tier, app tier) and version them independently.

StackSets deploy a single template across accounts and Regions. Use the service-managed permission model with AWS Organizations to auto-deploy to OUs and automatically include new accounts. Configure operation preferences (max concurrent accounts/Regions, failure tolerance) to control rollout. Parameter overrides per account or Region let you adapt a standard template to local constraints. Monitor StackSet and stack instance drift to detect out-of-band changes.

Change sets provide safe, human-reviewable updates. Always CreateChangeSet and inspect the resource-by-resource impact, replacements, and potential data loss before ExecuteChangeSet. Integrate change sets into automated pipelines for gated approvals.

Drift detection validates that stack resources match the template. Run drift detection routinely on critical stacks and StackSets; understand that not all properties are evaluated for all resource types (unsupported properties report as “not checked”). Treat drift as an incident: investigate, capture context, and correct either by stack update or by codifying the drift and reapplying.

Stack policies are JSON documents that protect critical resources during updates. Deny updates to irreplaceable resources (for example, production databases, Route 53 zones) and use StackPolicyDuringUpdateBody to temporarily open a surgical path for a specific change, then restore the stricter policy. Combine with termination protection and DeletionPolicy (Retain/Snapshot) for guardrails. For resources with external state (S3 buckets), plan deletion behaviors. If a bucket must be emptied before deletion, implement a custom resource to purge objects on stack delete.

AWS CDK and CloudFormation Extensibility

AWS CDK models infrastructure in familiar languages (TypeScript, Python, Java, .NET, Go). Constructs are the CDK building blocks:

A CDK app contains one or more stacks. During cdk synth, the app resolves context lookups (for example, VPC IDs), renders assets, and produces a CloudFormation template. Before you deploy, cdk bootstrap creates the environment’s asset buckets and roles. Use cdk diff to preview changes, then cdk deploy to submit templates and assets; CDK internally uses change sets and will show and confirm security-sensitive changes (IAM or resource replacements). Tag stacks and resources through Aspects to enforce organization-wide tagging. Where L2 abstractions fall short, use escape hatches (node.defaultChild) or drop to L1 constructs.

CloudFormation custom resources extend IaC to anything accessible via APIs. A Lambda-backed custom resource receives Create, Update, and Delete events with a RequestId, PhysicalResourceId, and properties. The function must:

Use least-privilege IAM execution roles for the Lambda, include exponential-backoff on API calls, and log correlation via the RequestId. For large or long-running operations, consider Step Functions with a custom resource that waits on an execution token. Prefer the CloudFormation Registry for reusable, versioned providers when applicable.

Secrets and Parameters in Infrastructure as Code

Never hardcode secrets in templates or code. Use dynamic references to resolve sensitive values at deploy time:

Dynamic references prevent secrets from being stored in the stack template or events. Do not place secrets in Outputs or resource properties that CloudFormation logs as plaintext. Grant CloudFormation’s execution role permission to decrypt or retrieve referenced values, and scope KMS CMKs to principals that need access.

Parameter Store is ideal for non-secret configuration (feature flags, AMI IDs, endpoints). Use versioned SSM parameters to create safe rollbacks and atomic promotions across environments. In CDK, import values with ssm.StringParameter.fromStringParameterName or fromSecureStringParameterAttributes for secure values, and wire parameter reads into user data or application bootstraps.

Secrets Manager is designed for lifecycle controls, rotation, and auditing. Integrate rotation with supported engines (RDS, Aurora) or custom Lambdas. Reference secrets at runtime rather than baking into AMIs to avoid proliferation of stale material. For containerized or serverless workloads, inject secrets via environment variables backed by Secrets Manager references or mount via ECS/TaskDefinition secrets; rotate with minimal downtime by using short TTL connection pools and retries.

Configuration Management and Immutable Infrastructure

AWS OpsWorks provides opinionated configuration management. OpsWorks Stacks uses Chef cookbooks and lifecycle events (Setup, Configure, Deploy, Undeploy, Shutdown) to orchestrate application configuration and deployments, and supports auto-healing with health checks that stop/start or replace instances. Historically, OpsWorks also offered managed Chef Automate and Puppet Enterprise; today, many teams standardize on Systems Manager for agent-based orchestration or run Ansible/Chef/Puppet control planes themselves. Ansible is not natively integrated with OpsWorks; instead, use Systems Manager State Manager to run playbooks, or AWX/Ansible Automation Platform with SSM Session Manager connectivity and EC2 dynamic inventory.

AWS Systems Manager is the modern control plane for hybrid configuration:

Immutable infrastructure eliminates drift and accelerates rollback. EC2 Image Builder codifies image pipelines with:

Add test components to validate CIS benchmarks, agent health (SSM/CloudWatch), and application smoke checks. Version images and label with semantic tags. Publish AMI IDs to Parameter Store (for example, /app/frontend/ami) and reference in Auto Scaling launch templates. Deploy with rolling or blue/green strategies; replace instances instead of in-place patching to preserve immutability. Feed vulnerability scans (Amazon Inspector) into pipeline promotion gates. Do not bake secrets into images; retrieve at boot via Instance Metadata Service v2 and SSM/Secrets Manager references.

Practical Problem Scenario

Capital One needs to standardize multi-account, multi-Region deployments for a customer-facing platform while enforcing tight governance, secret management, and eliminating configuration drift. The environment spans hundreds of accounts in AWS Organizations, with strict controls around database access and OS hardening.

  1. Model infrastructure with AWS CDK and synthesize to CloudFormation
  1. Distribute baseline network and guardrail stacks via CloudFormation StackSets
  1. Protect critical resources with stack policies and change sets
  1. Extend IaC with Lambda-backed custom resources
  1. Centralize secrets and configuration with Secrets Manager and Parameter Store
  1. Enforce desired state and compliance via Systems Manager State Manager
  1. Adopt immutable infrastructure with EC2 Image Builder
  1. Pipeline orchestration and governance

CI · All domains · Monitoring

Practice these questions → · Timed practice on ExamRoll.io →

Pass the whole exam — not just this question

You found this answer. Get every verified question and explanation in one place, and save hours of prep. Free to start.

Pass your exam →

Browse Amazon →

Related guides

All-in-one access

One subscription. Every exam.

Every plan unlocks unlimited answer search, practice tests, AI explanations, and the full resource library — in 20+ languages.

Monthly
24.87
Just €0.83/day
Everything included:
  • Unlimited answer search
  • Unlimited practice tests
  • AI-powered explanations
  • Full resource library
  • 20+ languages
  • Weekly content updates
  • Rewards & referrals
  • Priority support
Start free trial

No credit card required*

Best value
12 months
179.87
Just €0.49/daySave 40%
Everything included:
  • Unlimited answer search
  • Unlimited practice tests
  • AI-powered explanations
  • Full resource library
  • 20+ languages
  • Weekly content updates
  • Rewards & referrals
  • Priority support
Start free trial

No credit card required*

✓ Free plan included · ✓ Cancel anytime · ✓ All plans unlock the full product