Templates, stacks and change sets, a full data-lake stack, intrinsic functions and dynamic references, safe deployments, CDK and SAM, and how they compare with Terraform.
AWS CloudFormation provisions AWS resources from templates (YAML or JSON). A deployed template is a stack; CloudFormation works out the order of creation, rolls back on failure, and tracks what it manages, so environments are reproducible and changes are reviewed as code.
Concept
Meaning
Template
Declares Parameters, Mappings, Conditions, Resources (required) and Outputs
Stack
One deployed instance of a template (e.g. data-lake-dev, data-lake-prod)
Change set
A preview of what an update will add, modify or replace, before executing it
Drift detection
Finds resources changed outside CloudFormation (e.g. by hand in the console)
Nested stacks
Reusable templates referenced from a parent stack
StackSets
Deploy the same stack to many accounts and regions
Keep buckets and databases (or take a final snapshot) if the stack or resource is deleted
UpdateReplacePolicy
Same protection when an update would replace the resource
Termination protection
Blocks accidental stack deletion
Stack policies
Forbid updates to critical resources
Change sets in CI/CD
Show "Replacement: True" before it happens: replacing a database or bucket can mean data loss
5. AWS CDK & SAM
The AWS CDK lets you define infrastructure in Python (or TypeScript, Java…) with loops, functions and sensible defaults; it synthesises CloudFormation templates.
# app.py: pip install aws-cdk-lib constructs ; deploy with: cdk deploy
from aws_cdk import App, Stack, RemovalPolicy, Duration
from aws_cdk import aws_s3 as s3, aws_lambda as _lambda, aws_s3_notifications as s3n
from constructs import Construct
class IngestStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
bucket = s3.Bucket(self, "Inbound",
encryption=s3.BucketEncryption.KMS_MANAGED,
block_public_access=s3.BlockPublicAccess.BLOCK_ALL,
enforce_ssl=True, versioned=True,
removal_policy=RemovalPolicy.RETAIN)
validator = _lambda.Function(self, "Validator",
runtime=_lambda.Runtime.PYTHON_3_12,
handler="handler.handler",
code=_lambda.Code.from_asset("lambda/validator"),
timeout=Duration.seconds(60))
bucket.grant_read(validator) # least-privilege policy generated for you
bucket.add_event_notification(s3.EventType.OBJECT_CREATED, s3n.LambdaDestination(validator),
s3.NotificationKeyFilter(prefix="incoming/", suffix=".csv"))
app = App()
IngestStack(app, "ingest-dev")
app.synth()
AWS SAM is a CloudFormation extension with short syntax for serverless resources (functions, APIs, event sources) and a CLI to build, test locally and deploy (sam build, sam local invoke, sam deploy --guided).
Tool
Strengths
Choose when
CloudFormation
Native, no extra tooling, stack rollback and drift detection
AWS-only, declarative templates, StackSets across accounts
AWS CDK
Real programming language, reusable constructs, less boilerplate
Developers who prefer code and abstractions
AWS SAM
Concise serverless syntax, local testing
Lambda-centric applications
Terraform
Multi-cloud, large provider ecosystem, plan/apply workflow
Multi-cloud or Databricks/SaaS resources alongside AWS
6. Common Interview Questions
Question
Short answer
What is a change set?
A preview of the adds, modifications and replacements an update will make, reviewed before executing
How do you protect a data bucket from stack deletion?
DeletionPolicy: Retain and UpdateReplacePolicy: Retain, plus termination protection and stack policies
!Ref vs !GetAtt?
!Ref returns a parameter value or the resource's primary identifier; !GetAtt returns a named attribute such as an ARN
How do you pass secrets to resources?
Dynamic references to Secrets Manager or SSM Parameter Store, resolved at deploy time; never plain text parameters
What is drift?
Differences between the template and real resources caused by manual changes; detect and reconcile them
CloudFormation vs CDK vs Terraform?
CloudFormation: native declarative AWS. CDK: code that generates CloudFormation. Terraform: multi-cloud declarative tool with its own state