CloudFormation and CDK Flashcards
What is AWS CloudFormation?
A declarative service to outline and manage AWS infrastructure as code.
What are the benefits of CloudFormation?
Infrastructure as code, version control, cost estimation, productivity, reusable templates.
How does CloudFormation work?
Templates define resources, uploaded to S3, and referenced by CloudFormation to create/update stacks.
What happens when a stack is deleted?
All resources created by the stack are deleted.
What are CloudFormation building blocks?
Resources (mandatory), Parameters, Mappings, Outputs, Conditionals, References, Functions.
Which languages are used for CloudFormation templates?
YAML and JSON; YAML is preferred.
What are CloudFormation resources?
Core components of a template that define AWS infrastructure.
Can CloudFormation create dynamic number of resources?
Yes, using Macros and Transforms.
What are CloudFormation Parameters?
Inputs to templates for reuse and dynamic configuration.
When should you use Parameters?
When values are user-specific or likely to change.
What are CloudFormation Mappings?
Fixed variables to differentiate values like region or environment.
How to access Mapping values?
Use Fn::FindInMap.
When to use Mappings vs Parameters?
Mappings for predictable values, Parameters for dynamic inputs.
What are CloudFormation Outputs?
References to created resources; can be exported for cross-stack use.
How to use cross-stack references?
Use Fn::ImportValue in the referencing stack.
What are CloudFormation Conditions?
Logic to create resources based on parameter values or environment.
How to use a Condition in a resource?
Attach a Condition with logical functions like Fn::If.
What is Fn::Ref used for?
Reference parameters and resources.
What does Fn::GetAtt do?
Get attributes from a resource (e.g., AZ from an EC2 instance).
What does Fn::Base64 do?
Encodes a string to Base64, e.g., for EC2 UserData.
What happens when stack creation fails?
Rolls back all created resources unless rollback is disabled.
What is a CloudFormation Service Role?
IAM role to allow CFN to manage resources on your behalf.
What are CAPABILITY_NAMED_IAM and CAPABILITY_IAM?
Capabilities to allow creation of IAM resources via CloudFormation.
What is CAPABILITY_AUTO_EXPAND?
Used when templates use Macros or Nested Stacks.
What is DeletionPolicy in CloudFormation?
Controls what happens when a resource is deleted.
What does DeletionPolicy Retain do?
Keeps the resource after stack deletion.
What does DeletionPolicy Snapshot do?
Creates a snapshot before deleting a resource.
What is a Stack Policy?
Defines what resources can be updated during a stack update.
How to prevent accidental stack deletion?
Enable TerminationProtection.
What are Custom Resources in CloudFormation?
Define custom provisioning logic using Lambda or SNS.
What is a use case for Custom Resources?
Empty an S3 bucket before deletion.
What are CloudFormation StackSets?
Manage stacks across multiple accounts and regions from one template.
What is AWS CDK?
A framework to define cloud infrastructure using programming languages like JavaScript, TypeScript, Python, Java, and .NET.
What are CDK constructs?
Components that encapsulate everything CDK needs to create the final CloudFormation stack.
What is the purpose of CDK synth?
It synthesizes and prints the CloudFormation template from your CDK code.
What is CDK bootstrap?
It deploys the CDK Toolkit stack that includes necessary resources like an S3 bucket and IAM roles.
What are CDK L1 constructs?
Low-level constructs mapped directly to CloudFormation resources, names start with ‘Cfn’.
What are CDK L2 constructs?
Higher-level constructs with convenient defaults and intent-based APIs.
What are CDK L3 constructs?
High-level patterns that include multiple related AWS resources for common architectures.
What does ‘cdk deploy’ do?
Deploys the stack(s) to AWS.
What does ‘cdk diff’ do?
Compares local CDK stack with the deployed stack and shows the differences.
What is the use of ‘cdk destroy’?
Destroys the deployed stack(s) in AWS.
What is CDK Toolkit?
A CloudFormation stack created by CDK bootstrap containing an S3 bucket and IAM roles.
What happens if CDK is not bootstrapped?
You get an error about invalid principal in the policy.
How can CDK be tested?
Using CDK Assertions with test frameworks like Jest or Pytest.
What are fine-grained assertions in CDK testing?
Tests that check specific aspects of a resource in the CloudFormation template.
What are snapshot tests in CDK?
Tests that compare the synthesized template to a stored baseline template.
How to initialize a CDK app?
Use the command ‘cdk init app’.
What command installs the CDK CLI?
npm install -g aws-cdk-lib
What command deploys resources using CDK?
cdk deploy
What command destroys a CDK stack?
cdk destroy
What is the Construct Hub in CDK?
A collection of additional constructs provided by AWS, 3rd parties, and the open-source community.