Create an (Free tier Linux) EC2 using the CloudFormation Template -1

Sri
3 min readMar 24, 2024

--

AWS CloudFormation is a service that allows developers to create AWS resources in a predictable way using text files. (YAML /JSON)

These files, also known as templates, are the single source of truth for infrastructure and are an important “infrastructure as code” artifact.

Deploying CloudFormation template

CloudFormation Templates can be deployed as: 1.Manual way 2.Automated way

Using Cloud Formation Console to deploy EC2 instance

1. Log in to AWS Console > Search for CloudFormation

2. In Cloud Formation console > Click Create Stack

3.Choose the below options

4.Click choose file ..

· Copy file from below link and save it as YAML and choose that file.

·https://github.com/SRIDEVI24/Projects/blob/fae953d44bd9b4431b2c223e9800ac882ab0bbd1/AWS%20Projects/CLOUD%20FORMATION/ec2-simple_1.yaml

OR

· Copy the below code and save it as .yaml file.Change the ImageID and instance type as required by referring to the AWS EC2 AMI image console.

AWSTemplateFormatVersion: 2010-09-09
Description:
Sample template to create EC2 in free-tier account.
Linux al2023-ami-2023.4.20240319.1-kernel-6.1-x86_64 in Availablity zone us-east-1a
You will be billed for the AWS resources used ,
if you create a stack from this template.
After deleting stack, remember to delete the associated S3 bucket.

Resources:

# EC2 instance of type t2.micro
CloudFormedEC21A:
Type: 'AWS::EC2::Instance'
Properties:
InstanceType: t2.micro
ImageId: ami-0c101f26f147fa7fd
AvailabilityZone: us-east-1a
Tags:
- Key: Name
Value: CloudFormed-ec2-1A
- Key: Application
Value:
Ref: "AWS::StackName"

# output important values for easy viewing in cloudformation dashboard
Outputs:
InstanceId1A:
Description: InstanceId of the first EC2 instance
Value: !Ref CloudFormedEC21A

5.Choose file and click next

6. Provide stack name

7.Continue with default options and create Stack

8. Stack Name >Events

9. EC2 instances is launched and is visible in the Events tab

10. The Output parameters mentioned in .YAML file seeen in the Output tab

11.AWS Console > Ec2 instance > Find the Ec2 instance created as specified in the .YAML file

Please note the tags of the EC2 instances

12.Note that the YAML file is stored in S3 bucket.

Next, we will see how to add two security groups on this EC2 instance.Till then,Happy Learning !

--

--