Resource Declaration Syntax
What you'll learn: How to properly declare AWS resources in CloudFormation templates using Type, Properties, and logical IDs.
The Core Structure
Every AWS resource you create in CloudFormation follows a consistent syntax pattern. Think of it like filling out a form: you need to give your resource a name (logical ID), specify what kind of resource it is (Type), and provide the details about how to configure it (Properties).
The Three Essential Components
Logical ID
This is the unique name you choose to identify the resource within your template. It's like a nickname you'll use to reference this resource elsewhere. For example: MyWebServer or AppDatabase.
Type
This declares what AWS service and resource you're creating. It always follows the pattern AWS::Service::Resource. For example:
AWS::EC2::Instancefor an EC2 instanceAWS::S3::Bucketfor an S3 bucketAWS::RDS::DBInstancefor a database
Properties
These are the specific configuration settings for your resource—like instance size, bucket name, or database engine. Each resource type has its own set of available properties.
Basic Syntax Example
Resources:
MyLogicalID:
Type: AWS::S3::Bucket
Properties:
BucketName: my-unique-bucket-name
In this example:
MyLogicalIDis the logical IDAWS::S3::Bucketis the TypeBucketNameis a Property of the bucket
All resource declarations go under the Resources: section of your template.
Key Takeaway: Every CloudFormation resource requires a logical ID (your custom name), a Type (the AWS resource type), and Properties (configuration details)—this three-part structure is the foundation of infrastructure-as-code with CloudFormation.