Mastering AWS CloudFormation Template Anatomy: A Beginner-Friendly Guide | by Adi_Kodz | Oct, 2024

AWSTemplateFormatVersion: “2010-09-09”
Description: “Sample template to create an EC2 instance and an S3 bucket.”

Parameters:
InstanceTypeParameter:
Type: String
Default: t2.micro
AllowedValues: [t2.micro, t2.small, t2.medium]
Description: “Type of EC2 instance to create.”

Mappings:
RegionMap:
us-east-1:
AMI: ami-0abcd1234abcd5678
eu-west-1:
AMI: ami-1bcde234abcd67890

Resources:
MyEC2Instance:
Type: AWS::EC2::Instance
Properties:
InstanceType: !Ref InstanceTypeParameter
ImageId: !FindInMap [RegionMap, !Ref “AWS::Region”, AMI]

MyS3Bucket:
Type: AWS::S3::Bucket

Outputs:
InstancePublicIP:
Description: “Public IP of the EC2 instance.”
Value: !GetAtt MyEC2Instance.PublicIp