Get ready for your next interview with our comprehensive question library
AWS CloudFormation is a service that helps you model and set up your AWS resources using Infrastructure as Code (IaC). It solves several key problems:
The main components are:
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Simple web server template'
Parameters:
InstanceType:
Type: String
Default: t2.micro
Resources:
WebServer:
Type: AWS::EC2::Instance
Properties:
InstanceType: !Ref InstanceType
ImageId: ami-0abcdef1234567890
Outputs:
InstanceId:
Value: !Ref WebServer
YAML Advantages:
# YAML
Resources:
MyBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: my-example-bucket
{
"Resources": {
"MyBucket": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName": "my-example-bucket"
}
}
}
}
Most teams prefer YAML for readability and maintainability.
When stack creation fails:
ROLLBACK_COMPLETE
state--disable-rollback
flag only for debuggingaws cloudformation describe-stack-events --stack-name my-stack
CloudFormation supports these parameter types:
Basic Types:
String
: Text valuesNumber
: Numeric values CommaDelimitedList
: List of values separated by commasAWS::EC2::KeyPair::KeyName
: EC2 Key Pair namesAWS::EC2::SecurityGroup::Id
: Security Group IDsAWS::EC2::Subnet::Id
: Subnet IDsAWS::EC2::VPC::Id
: VPC IDsAWS::Route53::HostedZone::Id
: Route 53 Hosted Zone IDsList<Number>
: List of numbersList<AWS::EC2::Subnet::Id>
: List of subnet IDsParameters:
Environment:
Type: String
AllowedValues: [dev, staging, production]
Default: dev
SubnetIds:
Type: List<AWS::EC2::Subnet::Id>
Description: Subnets for load balancer
InstanceCount:
Type: Number
MinValue: 1
MaxValue: 10
Default: 2
CloudFormation:
Upgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumAccess all premium content - interview questions, and other learning resources
We regularly update our features and content, to ensure you get the most relevant and updated premium content.
1000 monthly credits
Cancel anytime