What are the main components of a CloudFormation template?

Beginner

Answer

The main components are:

  1. AWSTemplateFormatVersion (Optional): Specifies the template format version
  2. Description (Optional): Human-readable description of the template
  3. Parameters (Optional): Input values for the template
  4. Mappings (Optional): Static lookup tables
  5. Conditions (Optional): Controls resource creation based on conditions
  6. Resources (Required): AWS resources to create
  7. Outputs (Optional): Values returned when viewing stack properties
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