📖 Scenario: You are setting up a simple AWS CloudFormation template to create infrastructure automatically. This template will define resources like an S3 bucket and an EC2 instance.
🎯 Goal: Build the Resources section of a CloudFormation template with two resources: an S3 bucket named MyBucket and an EC2 instance named MyInstance.
📋 What You'll Learn
Create a CloudFormation template dictionary named template with a Resources key.
Add an S3 bucket resource with logical ID MyBucket and type AWS::S3::Bucket.
Add an EC2 instance resource with logical ID MyInstance and type AWS::EC2::Instance.
Set the EC2 instance property InstanceType to t2.micro.
💡 Why This Matters
🌍 Real World
CloudFormation templates automate AWS infrastructure setup, saving time and reducing errors.
💼 Career
Understanding how to define resources in CloudFormation is essential for cloud engineers and DevOps professionals managing AWS environments.
Progress0 / 4 steps
1
Create the initial CloudFormation template dictionary
Create a dictionary called template with an empty Resources dictionary inside it.
AWS
Hint
Start by creating a dictionary named template with a key Resources set to an empty dictionary.
2
Add the S3 bucket resource
Add a resource to template["Resources"] with the key MyBucket. Set its Type to AWS::S3::Bucket.
AWS
Hint
Inside the Resources dictionary, add a key MyBucket with a dictionary value that has a Type key set to AWS::S3::Bucket.
3
Add the EC2 instance resource with properties
Add a resource to template["Resources"] with the key MyInstance. Set its Type to AWS::EC2::Instance and add a Properties dictionary with InstanceType set to t2.micro.
AWS
Hint
Add a new key MyInstance in Resources with the specified type and properties.
4
Complete the CloudFormation template
Ensure the template dictionary includes both MyBucket and MyInstance resources correctly structured under Resources.
AWS
Hint
Review the entire template dictionary to confirm both resources are present and correctly defined.
Practice
(1/5)
1. What is the main purpose of the Resources section in an AWS CloudFormation template?
easy
A. To define the cloud parts AWS should create
B. To specify user permissions
C. To write code logic for the application
D. To store data in the cloud
Solution
Step 1: Understand the role of the Resources section
The Resources section lists all the cloud components AWS will build, like servers or databases.
Step 2: Compare with other template sections
Other sections handle permissions or outputs, but Resources is for creating cloud parts.
Final Answer:
To define the cloud parts AWS should create -> Option A
Quick Check:
Resources section = define cloud parts [OK]
Hint: Resources section always defines what AWS builds [OK]
Common Mistakes:
Confusing Resources with Permissions or Outputs
Thinking Resources stores data
Assuming Resources runs application code
2. Which of the following is the correct way to start defining a resource named MyBucket of type AWS::S3::Bucket in the Resources section?
easy
A. "MyBucket": "AWS::S3::Bucket"
B. "Type": "AWS::S3::Bucket", "MyBucket": {}
C. "MyBucket": { "Type": "AWS::S3::Bucket" }
D. "AWS::S3::Bucket": { "MyBucket": {} }
Solution
Step 1: Check resource name and type syntax
Each resource needs a unique name as key, then a block with a Type property.
Step 2: Match correct JSON structure
"MyBucket": { "Type": "AWS::S3::Bucket" } correctly uses the resource name as key and sets Type inside an object.
Final Answer:
"MyBucket": { "Type": "AWS::S3::Bucket" } -> Option C
Quick Check:
Resource name as key + Type property = "MyBucket": { "Type": "AWS::S3::Bucket" } [OK]
Hint: Resource name is key, Type is inside its object [OK]
Common Mistakes:
Putting Type outside resource object
Using resource type as key instead of name
Missing curly braces for resource details
3. Given this Resources snippet in a CloudFormation template:
BucketName must be text (string), but 12345 is a number here.
Step 2: Validate other parts
Type and Properties exist and resource name is valid, so no error there.
Final Answer:
BucketName must be a string, not a number -> Option B
Quick Check:
BucketName requires string value = BucketName must be a string, not a number [OK]
Hint: BucketName must be quoted text, not a number [OK]
Common Mistakes:
Using numbers instead of strings for names
Misnaming resource types
Omitting Properties section
5. You want to create two resources in your template: an S3 bucket named MyDataBucket and an EC2 instance named MyWebServer. Which Resources section snippet correctly defines both with minimal required properties?