AWS Infrastructure as Code Interview Questions and Answers: CloudFormation, CDK, CLI, Terraform and CI/CD (50 Questions)
This page has 50 new interview questions on infrastructure as code, the AWS CLI and CI/CD on AWS, with full answers. Almost every DevOps and cloud engineer interview now asks how you build and change infrastructure safely with code.
1. An everyday example: a building plan
Clicking in the console is fine for learning, but it is slow, error-prone and hard to repeat. Companies want environments that can be built, reviewed and rebuilt the same way every time. Interviewers check if you can do that safely.
Think of building a house. The template is the architect's drawing. The stack is the house built from that drawing. A change set is the list of changes the contractor shows you before breaking any wall. Drift is when someone changes the house without updating the drawing. The CLI is your phone call to the builder for quick jobs. A CI/CD pipeline is the approved process: design, check, build, inspect, hand over.
How to use this page
- For every IaC answer, mention review (diff or change set), safe rollout and rollback.
- Practise the CLI commands with
--dry-runor read-only calls first. - Know at least one tool well (CloudFormation, CDK or Terraform) and be able to compare them.
2. Fresher level questions
Start here if you are a fresher or have less than two years of experience. Try to answer each question aloud first. Then open it and compare.
Q1. What is infrastructure as code (IaC)? Fresher
IaC means you describe your infrastructure, such as VPCs, servers, databases and permissions, in code files instead of clicking in the console.
Why: the same code builds dev, test and prod the same way. Changes are reviewed in Git, tested, and can be rolled back. Nothing depends on one person's memory.
Tools on AWS: CloudFormation, AWS CDK, AWS SAM and Terraform.
Everyday example: a recipe written down, so any cook can make the same dish again.
Q2. How can one CloudFormation template create both the dev and prod environments? Fresher
A template is a JSON or YAML file that describes the resources you want, such as an S3 bucket and an IAM role.
A stack is a running set of resources that CloudFormation created from a template. You create, update and delete resources by creating, updating and deleting the stack.
One template can create many stacks, for example dev and prod, using different parameters.
Q3. What are the main sections of a CloudFormation template? Fresher
- AWSTemplateFormatVersion and Description: optional information.
- Parameters: inputs, such as EnvironmentName or InstanceType.
- Mappings: fixed lookup tables, such as AMI IDs per Region.
- Conditions: create resources only when true, such as only in prod.
- Resources: the only required section. It lists what to create.
- Outputs: values to show or export, such as the ALB DNS name.
Others include Metadata, Rules and Transform (used by SAM).
Q4. What do Ref and Fn::GetAtt return in CloudFormation? Fresher
Ref returns the default value of a resource or parameter. For many resources it is the physical ID, such as a bucket name or an instance ID. For a parameter, it returns the parameter's value.
Fn::GetAtt returns a specific attribute of a resource, such as the Arn of a role or the DNSName of a load balancer.
Example: !Ref AppBucket gives "shop-assets-dev", while !GetAtt AppBucket.Arn gives "arn:aws:s3:::shop-assets-dev".
Q5. How do you deploy a CloudFormation template from the CLI? Fresher
Use aws cloudformation deploy. It creates the stack if it does not exist, or updates it through a change set.
aws cloudformation deploy --stack-name shop-network-dev --template-file network.yaml --parameter-overrides EnvName=dev VpcCidr=10.20.0.0/16 --tags Project=shopOutput:
Waiting for changeset to be created..
Waiting for stack create/update to complete
Successfully created/updated stack - shop-network-devThe stack was created or updated. If the template creates IAM resources, add --capabilities CAPABILITY_IAM or CAPABILITY_NAMED_IAM.
Q6. What happens when a CloudFormation stack creation fails? Fresher
By default, CloudFormation rolls back. It deletes the resources it created for that stack, and the stack ends in ROLLBACK_COMPLETE.
A stack in ROLLBACK_COMPLETE cannot be updated. You must delete it and create it again after fixing the template.
To debug, open the stack Events tab and find the first CREATE_FAILED event. That shows the real reason, such as a name conflict or missing permission.
During development you can choose to preserve successfully provisioned resources, so you can fix and retry faster.
Q7. What is the AWS CDK? Fresher
The AWS Cloud Development Kit lets you define infrastructure using programming languages such as TypeScript, Python, Java, C# or Go.
Your code builds a tree of constructs. cdk synth turns it into a CloudFormation template, and cdk deploy deploys it through CloudFormation.
Benefits: loops, functions, classes, IDE help, and high-level constructs that create many resources with safe defaults in a few lines.
Q8. How do you configure the AWS CLI with multiple accounts? Fresher
Use named profiles.
- For IAM Identity Center, run
aws configure ssoand choose the account and role. It writes a profile into ~/.aws/config. - Use a profile with
--profile shop-devor by settingexport AWS_PROFILE=shop-dev. - Log in again when the session expires with
aws sso login --profile shop-dev.
Profiles let you switch between dev and prod safely. Many teams add the account name in the shell prompt to avoid running commands in the wrong account.
Q9. What output formats does the AWS CLI support? Fresher
The CLI supports json (default), yaml, yaml-stream, text and table.
- json: best for scripts with jq.
- text: tab-separated, easy for shell loops.
- table: easy to read for humans.
Set the default in ~/.aws/config with output = json, or per command with --output table.
Combine with --query to select only the fields you need.
Q10. What is the --query option in the AWS CLI? Fresher
--query filters and reshapes the output on your side using the JMESPath language.
aws ec2 describe-volumes --query "Volumes[?State=='available'].{id:VolumeId,size:Size,az:AvailabilityZone}" --output tableOutput:
-------------------------------------------
| DescribeVolumes |
+--------------+-------------------------+-------+
| az | id | size |
+--------------+-------------------------+-------+
| ap-south-1a | vol-0a1b2c3d4e5f60009 | 100 |
+--------------+-------------------------+-------+One 100 GiB volume is "available", which means not attached to any instance. It may be wasting money. --filters works on the server side, while --query works after the data arrives.
Q11. What is AWS SAM? Fresher
AWS SAM (Serverless Application Model) is an extension of CloudFormation for serverless apps.
It has short resource types, such as AWS::Serverless::Function and AWS::Serverless::Api, which expand into full CloudFormation resources through a Transform.
The SAM CLI can build, test functions locally, and deploy with sam deploy --guided.
It also supports gradual Lambda deployments with CodeDeploy using a simple setting.
Q12. What is Terraform and how does it work with AWS? Fresher
Terraform is a popular IaC tool from HashiCorp. Newer versions use the Business Source License. OpenTofu is an open-source fork with the same workflow.
You write configuration in HCL. The AWS provider turns it into AWS API calls.
Workflow: terraform init downloads providers, terraform plan shows changes, and terraform apply makes them.
Terraform keeps a state file that maps your code to real resources. For teams, store state remotely, such as in an S3 bucket with locking, encryption and versioning.
Q13. What is a CI/CD pipeline? Fresher
CI (continuous integration) means every code change is built and tested automatically.
CD (continuous delivery or deployment) means tested changes are released to environments automatically, sometimes with a manual approval before production.
A typical AWS pipeline: source in a Git provider, build and test in CodeBuild, deploy with CloudFormation, CodeDeploy or ECS, and approval steps in CodePipeline.
The goal is small, frequent and safe releases.
Q14. What is a buildspec file in CodeBuild? Fresher
buildspec.yml tells CodeBuild what to do. It has phases:
- install: install runtimes and tools.
- pre_build: log in to ECR, run linters.
- build: compile, test, build the Docker image.
- post_build: push the image, write output files.
It also lists artifacts to save and reports for test results.
CodeBuild runs it in a fresh container each time, so builds are clean and repeatable.
Q15. What are CloudFormation Outputs and exports? Fresher
Outputs show useful values after deployment, such as the website URL.
If you add an Export name, other stacks in the same account and Region can import the value with Fn::ImportValue.
Example: the network stack exports the VPC ID, and the app stack imports it.
Note: you cannot delete or change an export while another stack imports it. This protects dependencies, but it can block changes, so use exports carefully.
Q16. How do you see what the AWS CLI is doing when a command fails? Fresher
Add --debug to the command. It prints the configuration source, the credentials provider used, the endpoint, the HTTP request and the response.
Common findings:
- The wrong profile or Region is being used.
- Credentials have expired.
- The endpoint is blocked by a proxy or firewall.
Also run aws configure list to see which profile, keys source and Region are active, and aws sts get-caller-identity to see who you are.
Q17. What is the order in which the AWS CLI looks for credentials? Fresher
The CLI uses the first credentials it finds, in this order:
- Command line options, such as --profile.
- Environment variables, such as AWS_ACCESS_KEY_ID and AWS_PROFILE.
- Web identity token settings (used in EKS and CI with OIDC).
- The shared credentials and config files (~/.aws/credentials and ~/.aws/config), including SSO profiles.
- Container credentials (ECS task role).
- Instance profile credentials (EC2 role).
Old environment variables in a shell are a common reason for "why am I in the wrong account?".
3. Mid level questions
These questions check how you use the service in real projects. Interviewers expect the why, the how and one real example.
Q18. Why should a production CloudFormation update always start with a reviewed change set? Mid level
A change set is a preview of what an update will do before it runs.
It lists each resource that will be added, modified or removed, and whether a modification needs replacement.
Replacement matters: for some properties, such as a database identifier, CloudFormation must create a new resource and delete the old one, which could lose data.
Best practice: always create and review a change set for production updates, ideally in the pipeline with an approval step.
Q19. Someone edited a security group in the console. How does CloudFormation find it, and how do you fix it? Mid level
Drift happens when someone changes a resource outside CloudFormation, for example editing a security group in the console.
Drift detection compares the live configuration with the template and marks resources as IN_SYNC, MODIFIED or DELETED, with the exact property differences.
Fix drift by updating the template to match the desired state and redeploying, or by importing changes. Prevent it with IAM rules that block manual changes in production.
Q20. What are DeletionPolicy and UpdateReplacePolicy? Mid level
DeletionPolicy controls what happens to a resource when it is removed from the stack or the stack is deleted:
- Delete (default for most resources).
- Retain: keep the resource.
- Snapshot: take a final snapshot, for supported resources like RDS and EBS volumes.
- RetainExceptOnCreate: retain, except when the stack creation itself fails.
UpdateReplacePolicy does the same for the old resource when an update needs replacement.
Use Retain or Snapshot on databases and important buckets.
Q21. What are nested stacks and StackSets? Mid level
Nested stacks: a parent stack creates child stacks with AWS::CloudFormation::Stack. Use them to reuse common parts, such as a standard VPC, and to keep templates small.
StackSets: deploy the same stack to many accounts and Regions from one place. With service-managed permissions and AWS Organizations, new accounts in an OU can get the stack automatically.
Example: StackSets deploy a baseline of Config rules and an IAM audit role to every account.
Q22. How do you pass secrets into CloudFormation without exposing them? Mid level
Use dynamic references. The template refers to the secret, and CloudFormation fetches the value at deploy time.
Example: MasterUserPassword: '{{resolve:secretsmanager:shop/db:SecretString:password}}'.
For RDS you can also use ManageMasterUserPassword, so RDS creates and stores the password in Secrets Manager for you.
Do not put secrets in parameters with default values or in the template body. If you must use a parameter, set NoEcho to true, but remember it is not a full secret store.
Q23. What are CloudFormation custom resources? Mid level
A custom resource lets you run your own logic during stack create, update and delete, usually with a Lambda function.
Use it when CloudFormation does not support something, for example calling a third-party API or doing a one-time data setup.
The function must always send a SUCCESS or FAILED response, including on delete. If it does not, the stack waits until a timeout.
Before writing one, check whether a native resource type, a registry extension, or a CDK construct already exists.
Q24. What are CDK construct levels L1, L2 and L3? Mid level
- L1 constructs map one-to-one to CloudFormation resources, such as CfnBucket. You set every property yourself.
- L2 constructs are higher-level classes with sensible defaults and helper methods, such as s3.Bucket with bucket.grantRead(role).
- L3 constructs (patterns) combine many resources for a common use case, such as an ApplicationLoadBalancedFargateService that creates an ECS service, ALB and more.
Use L2 by default, L3 for quick standard patterns, and L1 when you need a feature not yet in L2.
Q25. What does cdk bootstrap do? Mid level
Bootstrapping prepares an account and Region for CDK deployments.
It creates a stack called CDKToolkit with an S3 bucket for file assets, an ECR repository for image assets, and IAM roles that CDK uses to deploy.
cdk bootstrap aws://111122223333/ap-south-1 run it once per account and Region. For cross-account pipelines, bootstrap target accounts with --trust for the pipeline account, and use --cloudformation-execution-policies to limit what deployments can create.
Q26. How do you test infrastructure code before deploying? Mid level
Use several layers.
- Linting and validation: cfn-lint,
terraform validate,cdk synth. - Policy checks: cfn-guard, Checkov or similar tools for rules like "all buckets encrypted".
- Unit tests: CDK assertions that check the synthesized template.
- Plan or change set review in the pipeline.
- Deploy to a test account and run integration tests, then destroy.
Catching mistakes before production is much cheaper than fixing them after.
Q27. How do you manage Terraform state safely for a team on AWS? Mid level
Keep state remote, locked, encrypted and backed up.
- Store state in an S3 bucket with versioning and encryption, and block public access.
- Use state locking so two people cannot apply at the same time. Recent Terraform versions support S3 native locking. Older setups use a DynamoDB table.
- Split state by environment and component, so one apply cannot break everything.
- Limit who can read state, because it can contain sensitive values.
- Run applies from a pipeline, not laptops.
Q28. How do you bring an existing manually created resource under IaC? Mid level
Import it instead of recreating it.
- CloudFormation: write the resource in the template with the same properties, add DeletionPolicy Retain, and use an IMPORT change set. The IaC generator can also scan existing resources and create a template.
- Terraform: use an import block or
terraform import, then run plan until it shows no changes. - CDK: use
cdk importfor supported resources.
After import, block manual changes so the code stays the source of truth.
Q29. How does CodeDeploy deploy to EC2 and what is the appspec file? Mid level
CodeDeploy deploys application revisions to EC2 or on-premises servers using an agent, and also supports ECS and Lambda.
appspec.yml defines where files go and which scripts run at lifecycle hooks, such as BeforeInstall, AfterInstall, ApplicationStart and ValidateService.
Deployment configurations control speed, such as one at a time, half at a time or all at once. With an ALB, CodeDeploy can take instances out of service during the update.
Rollback can be automatic when a deployment fails or an alarm fires.
Q30. How do you use CLI waiters and pagination? Mid level
Waiters poll until a resource reaches a state, so scripts do not need sleep loops.
aws ec2 wait instance-running --instance-ids i-0a1b2c3d4e5f60001 && echo "ready"The command returns when the instance is running, or fails after the waiter's maximum attempts.
Pagination: the CLI automatically fetches all pages by default. Use --max-items and --starting-token to control it, or --page-size to make smaller API calls and avoid timeouts on very large lists.
Q31. How do you write a safe bash script that uses the AWS CLI? Mid level
Good habits:
- Start with
set -euo pipefailso errors stop the script. - Set the profile and Region explicitly at the top, and print
aws sts get-caller-identitybefore making changes. - Use
--dry-runwhere supported, such as for EC2 actions, and a confirmation prompt for destructive steps. - Use --query and --output text for clean values, and quote all variables.
- Handle pagination and throttling, and log what the script changed.
- Never hard-code access keys in scripts.
Q46. What are CreationPolicy and cfn-signal used for? Mid level
By default, CloudFormation marks an EC2 instance as complete as soon as it starts, even if the app inside is still installing or has failed.
With a CreationPolicy, CloudFormation waits for a success signal. The instance's user data runs setup, then calls cfn-signal with the result.
If no success signal arrives before the timeout, the resource fails and the stack rolls back.
For Auto Scaling groups, the same idea with ResourceSignal count makes sure enough instances are healthy before the stack continues.
Q47. What is a stack policy in CloudFormation? Mid level
A stack policy is a JSON document that controls which resources can be updated during a stack update.
Example: allow updates to everything, but deny Update:Replace and Update:Delete on the production database.
It protects against mistakes in templates. It is not an IAM policy, and it only applies to stack updates, not to direct console or API changes.
To make an intended change to a protected resource, you supply a temporary override policy for that one update.
Q48. What do cdk diff and cdk synth show, and when do you use them? Mid level
cdk synth runs your CDK app and writes the CloudFormation templates into the cdk.out folder. Use it to check that the code compiles and to review the generated template.
cdk diff compares your app with the deployed stack and shows what will be added, changed or removed, including IAM and security group changes.
cdk diff ShopApiStackOutput:
Resources
[~] AWS::Lambda::Function OrdersFn
└─ [~] MemorySize
├─ [-] 512
└─ [+] 1024Only the function memory changes. Nothing is replaced or deleted, so the change is low risk.
Q49. What are CloudFormation parameter types for SSM and AWS-specific values? Mid level
Parameters can have AWS-specific types that CloudFormation checks before deploying.
- AWS::EC2::KeyPair::KeyName, AWS::EC2::VPC::Id and AWS::EC2::Subnet::Id: the value must exist in the account, and the console shows a drop-down list.
- AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>: the value is read from Parameter Store at deploy time, for example the latest Amazon Linux AMI public parameter.
This avoids hard-coded AMI IDs per Region and catches typing mistakes early.
4. Senior level and scenario questions
These questions check design thinking and troubleshooting. Think aloud. Say what you check first, what you change, and how you prevent it next time.
Q32. A CloudFormation stack is stuck in UPDATE_ROLLBACK_FAILED. What do you do? Senior
This state means the update failed and the rollback also failed, often because a resource was changed or deleted outside CloudFormation.
Steps:
- Read the events to find which resource could not roll back and why.
- Fix the cause if possible, for example recreate a deleted dependency or fix a permission.
- Run continue-update-rollback. If a resource still cannot roll back, use --resources-to-skip for that resource, after making sure skipping is safe.
- Once the stack is back to UPDATE_ROLLBACK_COMPLETE, fix the template and update again.
Never delete a production stack just to "clean up" without checking retained data.
Q33. How would you structure CloudFormation or CDK code for a large organisation? Senior
Split by lifecycle and ownership.
- Foundation stacks: networking, shared IAM, logging. Change rarely, owned by the platform team.
- Data stacks: databases, buckets. Protected with Retain policies and termination protection.
- Application stacks: compute, queues. Change often, owned by app teams.
- Share values through SSM parameters or exports, carefully.
- Reusable modules or CDK constructs with company standards, versioned in a library.
- StackSets or CDK pipelines for multi-account rollout.
Explain how this reduces blast radius and speeds up safe changes.
Q34. How do you prevent an IaC change from accidentally deleting a production database? Senior
Use several guards.
- DeletionPolicy and UpdateReplacePolicy set to Snapshot or Retain.
- DeletionProtection enabled on the RDS instance itself.
- Stack termination protection.
- A stack policy that denies Update:Replace and Update:Delete on the database resource.
- Change set or plan review in the pipeline with an automatic check that fails if a database will be replaced.
- Least-privilege deploy roles that cannot delete databases.
- Regular tested backups as the last line of defence.
Q35. How do you design a multi-account deployment pipeline? Senior
Use a dedicated tooling or deployment account.
- The pipeline runs in the tooling account and builds the artifact once.
- It assumes deploy roles in dev, staging and prod accounts. Each role trusts only the pipeline role.
- Promote the same artifact through stages with automated tests between them.
- Manual approval before prod, and deploy to prod in waves, such as one Region first.
- Encrypt artifacts with a KMS key that the target accounts can use.
- Alarms and automatic rollback after each stage.
Tools: CodePipeline, CDK Pipelines, GitHub Actions with OIDC, or similar.
Q36. Terraform plan shows that it will destroy and recreate an EC2 instance after a small change. What do you do? Senior
Do not apply blindly.
- Read the plan to see which attribute forces replacement, marked as "forces replacement".
- Common reasons: a change to the AMI ID, user data, subnet or availability zone.
- If the change was accidental, for example a data source that always picks the latest AMI, pin the value or use lifecycle ignore_changes for that attribute.
- If replacement is needed, use create_before_destroy, put the instance behind a load balancer or ASG, and plan a maintenance window.
- For stateful servers, take snapshots first.
Q37. How do you handle secrets in a CI/CD pipeline on AWS? Senior
Principles: no long-term keys, no secrets in Git, least privilege.
- Use OIDC federation from the CI tool to an IAM role, so builds get short-lived credentials.
- Store app secrets in Secrets Manager or Parameter Store. CodeBuild can load them into environment variables through the buildspec env section.
- Mask secrets in logs and avoid printing environment variables.
- Scan commits for secrets with a pre-commit hook and in the pipeline.
- Rotate secrets and review who can edit pipeline definitions, because pipeline edits can leak secrets.
Q38. How would you roll back a bad infrastructure change quickly? Senior
Plan rollback before the change.
- For CloudFormation, a failed update rolls back automatically. Rollback triggers can also roll back when a CloudWatch alarm fires during or after the update.
- For code-driven changes, revert the commit and let the pipeline redeploy the previous version.
- For app deployments, use blue/green or canary so rollback is just shifting traffic back.
- Keep data changes backward compatible, such as adding columns before removing old ones, so the old version still works after rollback.
Practise rollbacks, because untested rollback plans often fail.
Q39. How do you enforce company rules, like mandatory tags and encryption, across all IaC deployments? Senior
Use preventive and detective controls.
- Preventive in the pipeline: cfn-guard, Checkov or OPA policy checks fail the build if a rule is broken.
- Preventive in AWS: CloudFormation Hooks that check resources before they are created, SCPs, and tag policies in AWS Organizations.
- Reusable modules or CDK constructs with the rules built in, such as encryption on by default.
- Detective: AWS Config rules and Security Hub to catch anything created outside the pipeline.
Explain that shifting checks left is cheaper than fixing later.
Q40. What are the trade-offs between CloudFormation, CDK and Terraform? Senior
CloudFormation: AWS-native, managed state, StackSets, drift detection and automatic rollback. YAML can become long and repetitive.
CDK: real programming languages, high-level constructs and testing. It still deploys through CloudFormation, so CloudFormation limits apply. Needs developers comfortable with code.
Terraform: one workflow for many clouds and SaaS providers, large module ecosystem, and clear plans. You manage state, and licensing changed for newer versions.
A good answer chooses by team skills, multi-cloud needs and existing tools.
Q41. Two engineers applied Terraform at the same time and the state looks corrupted. How do you recover? Senior
First stop all applies.
- Check the state bucket's object versions and restore the last good state file version.
- Run terraform plan and compare with real resources. Use terraform import for resources that exist but are missing from state, and terraform state rm for entries that no longer exist.
- Turn on state locking so this cannot happen again.
- Move applies into a pipeline with one run at a time per state.
Document the incident and the fix.
Q42. How do you speed up a slow CI/CD pipeline? Senior
Measure each stage first.
- Cache dependencies and Docker layers in CodeBuild (local or S3 cache).
- Run tests in parallel and split slow test suites.
- Use larger or arm64 build instances where it helps.
- Build only what changed in a monorepo.
- Use smaller container images.
- Run security scans in parallel with tests, not after them.
- Deploy with incremental strategies, but keep safety checks.
Fast pipelines encourage small changes, which are safer.
Q43. How do you manage different configuration for dev, staging and prod with the same IaC code? Senior
Keep one codebase and change only inputs.
- CloudFormation parameters with separate parameter files per environment.
- CDK context or stage classes, where each stage gets its own config object.
- Terraform workspaces or separate root modules per environment with tfvars files.
- Store environment values that change at runtime in SSM Parameter Store.
Keep differences small: size and count can differ, but the architecture should be the same, so what you test in staging is what runs in prod.
Q44. How do you migrate from manual console-built infrastructure to IaC with no downtime? Senior
Go step by step.
- Inventory resources, using tags, AWS Config or Resource Explorer.
- Generate starting templates with the CloudFormation IaC generator or terraform import tooling.
- Import resources into stacks or state, starting with low-risk ones, and run plans until there are no differences.
- Add retain and protection settings to stateful resources.
- Move changes into a pipeline and lock down console write access in production.
- Clean up unused resources at the end.
Q45. How do you deploy Lambda and API changes with CDK safely in production? Senior
Combine CDK features with deployment controls.
- Use a CDK pipeline with stages for dev, staging and prod.
- Run
cdk diffin the pipeline and require approval for production. - Use Lambda aliases with CodeDeploy canary deployments and CloudWatch alarms for automatic rollback.
- Add cdk-nag or similar checks for security rules.
- Keep stateful resources in a separate stack with removal policies set to retain.
- Tag every resource with the version or commit.
Q50. How do you handle a large CloudFormation template that is hitting the resource limit per stack? Senior
A stack has a limit of 500 resources.
Options:
- Split it into nested stacks or separate stacks by lifecycle, such as network, data and app.
- Share values through exports, SSM parameters or stack parameters.
- Remove repeated resources with loops in CDK or the Fn::ForEach language extension, which shrinks the template but not the resource count.
- Reconsider design: for example, one Lambda per API route can create many resources, so group routes where it makes sense.
Splitting by lifecycle is usually the cleanest fix, and it also reduces blast radius.
5. Frequently asked questions
CloudFormation or Terraform: which should I learn?
Learn the ideas once: state, plan or change set, modules, drift. Then pick one tool deeply. Many companies use Terraform for multi-cloud and CloudFormation or CDK for AWS-only work. Interviewers respect clear trade-offs more than tool loyalty.
Do freshers get IaC questions?
Yes, basic ones: what is IaC, what is a stack, how to deploy a template, and how the CLI is configured.
How do I show IaC experience without a job?
Build a small project in a public Git repository: a VPC, an ALB and an Auto Scaling group with a pipeline. Explain your choices in the README. Never commit secrets or real account IDs.
6. Quick revision
- Always review a change set or diff before updating production.
- DeletionPolicy Retain or Snapshot protects important data resources.
- Fix drift by updating code, not by more manual changes.
- CLI credentials order: command options, environment variables, then config files and other providers.
- Pipelines should build once, then promote the same artifact through environments.
7. Related chapters
- AWS CloudFormation Deep Dive: Infrastructure as Code for Beginners
- AWS CLI CloudFormation Commands: Deploy, Update and Delete Stacks
- What Is AWS CDK? Cloud Development Kit in TypeScript and Python Explained
- How to Install and Configure AWS CLI v2: Profiles, SSO and Regions
- AWS CLI Output Formats, --query (JMESPath), Filters, Pagination and Waiters
- Terraform on AWS: Infrastructure as Code for Beginners
- AWS CodePipeline and CodeBuild: CI/CD on AWS Explained
- Serverless IaC: SAM vs Serverless Framework vs CDK Compared
This page is one part of a 500-question AWS interview set. Open the full list here: All 500 AWS interview questions.